Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Create SCCM 2007 Collections from CSV

$
0
0

Hi, I'm pretty new to powershell so any help would be appreciated!

I've created the following script to create a large number of SCCM collection based on a CSV containing AD Sites.

The script uses the snowland.se SCCM-Commands.psm1 module.

***********

Import-Module C:\Blah\SCCM-Commands.psm1
$SccmServer = "AU-GLB-SCM02"
$connecttoserver = Connect-SCCMServer -HostName $SccmServer -sitecode GL1
$newcollection = New-SCCMCollection -SccmServer $SccmServer -name "$adsite.site" -comment "$adsite.comment" -parentCollectionID "$adsite.parentcollection" -Verbose
$newqueryrule = Add-SCCMCollectionRule -Server $SccmServer -collectionID $newRoot.CollectionId -queryExpression "select *  from  SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = SMS_R_System.ResourceId inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_R_System.ADSiteName = "$adsite.site" and SMS_G_System_SYSTEM_ENCLOSURE.ChassisTypes in ("8","9","10","11","12","14","18","21") and SMS_G_System_COMPUTER_SYSTEM.Manufacturer not like "%VMware%"" -queryRuleName "$adsite.site" -limitToCollectionId "GL100A0B" -Verbose
$adsites = Import-CSV C:\Blah\test.CSV
foreach($adsite in $adsites) 
{
$newcollection
$newqueryrule
}

************

I'm getting the following error:

************

PS > c:\blah\createcollectionsforsites.ps1
Set-WmiInstance : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argume
nt that is not null or empty and then try the command again.
At C:\Blah\SCCM-Commands.psm1:394 char:95
+         $newColl = Set-WmiInstance -class "SMS_Collection" -arguments $arguments -computername <<<<  $SccmServer.Mach
ine -namespace $SccmServer.Namespace
    + CategoryInfo          : InvalidData: (:) [Set-WmiInstance], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SetWmiInstance

VERBOSE: Setting the new  parent to .parentcollection
Set-WmiInstance : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argume
nt that is not null or empty and then try the command again.
At C:\Blah\SCCM-Commands.psm1:426 char:111
+         $newRelation = Set-WmiInstance -Class "SMS_CollectToSubCollect" -arguments $subArguments -computername <<<<
$SccmServer.Machine -namespace $SccmServer.Namespace
    + CategoryInfo          : InvalidData: (:) [Set-WmiInstance], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SetWmiInstance

VERBOSE: Return the new collection with ID
Add-SCCMCollectionRule : Cannot bind argument to parameter 'collectionID' because it is null.
At C:\blah\createcollectionsforsites.ps1:6 char:73
+ $newqueryrule = Add-SCCMCollectionRule -Server $SccmServer -collectionID <<<<  $newRoot.CollectionId -queryExpression
 "select *  from  SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = S
MS_R_System.ResourceId inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_Syste
m.ResourceId where SMS_R_System.ADSiteName = "$adsite.site" and SMS_G_System_SYSTEM_ENCLOSURE.ChassisTypes in ("8","9",
"10","11","12","14","18","21") and SMS_G_System_COMPUTER_SYSTEM.Manufacturer not like "%VMware%"" -queryRuleName "$adsi
te.site" -limitToCollectionId "GL100A0B" -Verbose
    + CategoryInfo          : InvalidData: (:) [Add-SCCMCollectionRule], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Add-SCCMCollectionRule




Viewing all articles
Browse latest Browse all 15028

Trending Articles