· 6 years ago · Nov 05, 2019, 11:18 AM
1$OSDComputerName = $env:COMPUTERNAME
2
3$SecretKey = "ключ от вебсервиса"
4
5$SCCMServer = "sccm fqdn"
6$SiteCode = "сайт"
7
8$secpasswd = ConvertTo-SecureString "PASS" -AsPlainText -Force
9$Cred = New-Object System.Management.Automation.PSCredential ("ADMINACC", $secpasswd)
10
11$CollectionIDs = (Get-WmiObject -ComputerName $SCCMServer -Class SMS_DeploymentInfo -Namespace root\SMS\site_$SiteCode -Credential $Cred | Where-Object {$_.DeploymentType -eq "7"}).CollectionID
12
13# Construct web service proxy
14try {
15 $URI = "http://$SCCMServer/ConfigMgrWebService/ConfigMgr.asmx"
16 $WebService = New-WebServiceProxy -Uri $URI -ErrorAction Stop
17}
18catch [System.Exception] {
19 Write-Warning -Message "An error occured while attempting to calling web service. Error message: $($_.Exception.Message)" ; exit 2
20}
21
22# Remove computer from each collection in collections variable
23foreach ($CollectionID in $CollectionIDs) {
24 Write-Output -InputObject "Attempting to remove device '$($OSDComputerName)' from CollectionID: $($CollectionID)"
25 $Invocation = $WebService.RemoveCMDeviceFromCollection($SecretKey, $OSDComputerName, $CollectionID)
26}
27
28$host.setshouldexit(0)