I want to put a script at the end of the build to move a computer to a collection. Long story short, the SCCM Agent takes a bit too long after build so the hardware scan won’t run due to the SMS_Client not being populated. So this script is a kind of work around. So the details i’ve pulled so far are:
$SiteCode = “AAC”
$CMProvider = “Server”
$GetValues = New-Object -ComObject microsoft.sms.TSEnvironment
$OSDDepartment = $GetValues.Value(‘OSDDepartment’)
$OSDComputerName = $GetValues.Value(‘OSDComputerName’)
$TargetCollection = Get-WmiObject -Namespace “Root\SMS\Site_AAC” -Class SMS_Collection | Where-Object name -eq $OSDDepartment
$SourceCollection = Get-WmiObject -Namespace “Root\SMS\Site_AAC” -Class SMS_Collection | Where-Object name -eq “All Systems”
Get-WmiObject -Namespace “Root\SMS\Site_AAC” -Class SMS_G_System_COMPUTER_SYSTEM | where-object Name -eq “$OSDComputerName”
The method of Copy() i’m not sure how it works. But i can get the PC name during OSD and our “Department” branding variable created from an HTA. By referring to the SCCM server i can hopefully get around the SMS_Client local not being populated. The other way would be doing a test-connection a loop check every 30 seconds to see if the WMI SMS_Client has been created.
I hope this makes sense !