# powershell script to move a sms 2003 collection from one parent collection to another then
# request refresh of the parent collections
# replace the collection IDs with your own
# collection to move and its original and new parents collection IDs
$origParent = "C0100026" # collectionID of original parent of the collection to be moved
$coll2Move1 = "C01000B8" # ollectionID of the collection to be moved
$newParent = "C01002BC" # collectionID of the new parent of the collection to be moved
$collectionarray = $origParent,$newParent
$Computer = "your sms site server" # replace with your data
$CollectionClass = "SMS_Collection"
$collectToSubCollectionClass = "SMS_CollectToSubCollect"
$smsNameSpace = "root\SMS\your sms site code" # replace with your data
$Method = "RequestRefresh"
$c = Get-WmiObject -class $collectToSubCollectionClass -namespace $smsNameSpace -computerName $Computer
Where-Object {
$_.parentCollectionID -match $origParent -and $_.subCollectionID -match $coll2Move1
}
$c
# set new parent relationship
foreach ($item in $c)
{
Write-Host $c.parentCollectionID
Write-Host $c.subCollectionID
$c.parentCollectionID = $newParent
$c.put()
}
# delete old relationalship
$c = Get-WmiObject -class $collectToSubCollectionClass -namespace $smsNameSpace -computerName $Computer
Where-Object {
$_.parentCollectionID -match $origParent -and $_.subCollectionID -match $coll2Move1
}
$c.Delete()
#refresh collections
#adapted from SMS_Collection Method : RequestRefresh method script generated by PowerShell WmiExplorer
#
# /\/\o\/\/ 2006
# www.ThePowerShellGuy.com
#
foreach ($memb in $collectionarray)
{
write-host "The value in the current element is $memb"
# SMS_Collection. Key Properties :
# $CollectionID = $memb
$filter="CollectionID = '$memb'"
$MC = get-WMIObject $CollectionClass -computer $Computer -Namespace $smsNameSpace -filter $filter
# $MC = [Wmi]"\\$Computer\Root\CimV2:$Class.$filter"
$InParams = $mc.psbase.GetMethodParameters($Method)
$InParams.includesubcollections = $false
# "Calling SMS_Collection. : RequestRefresh with Parameters :"
$inparams.PSBase.properties select name,Value format-Table
$R = $mc.PSBase.InvokeMethod($Method, $inParams, $Null)
"Result :"
$R Format-list
}
Wednesday, August 1, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment