Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /var/www/fastuser/data/www/h2.ipnets.ru/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /var/www/fastuser/data/www/h2.ipnets.ru/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /var/www/fastuser/data/www/h2.ipnets.ru/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /var/www/fastuser/data/www/h2.ipnets.ru/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /var/www/fastuser/data/www/h2.ipnets.ru/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /var/www/fastuser/data/www/h2.ipnets.ru/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Мы все привыкли использовать Powershell для решения повседствевных задач автоматизации. Однако, использование Powershell для управления SCCM по прежнему остается непривиальной задачей.
Я сразу приведу несколько популярных примеров использования Powershell с WMI, чтобы выполнить типовые задачи администрирования CCM клиента:
Получить данные SCCM клиента: версию, сайт-код, MP сервер:
([wmiclass]"ROOT\ccm:SMS_Client").GetAssignedSite().sSiteCode ([wmi]"ROOT\ccm:SMS_Client=@").ClientVersion ([wmi]"ROOT\ccm:SMS_Authority.Name='SMS:PRI'").CurrentManagementPoint |
Получить машинную политику (machine policy) с сервера, а также сбросить политику:
([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000021}') |
Получить список доступных advertisements с SCCM сервера:
get-wmiobject -query "SELECT * FROM CCM_SoftwareDistribution" -namespace "root\ccm\policy\machine\actualconfig" |
или фильтруя по самым необходиымы полям
1 | get-wmiobject -query "SELECT * FROM CCM_SoftwareDistribution" -namespace "root\ccm\policy\machine\actualconfig" | select ADV_AdvertisementID, ADV_ExpirationTime, ADV_RepeatRunBehavior, PKG_Name, PKG_PackageID, PRG_CommandLine, PKG_SourceVersion, PRG_ProgramID |
Также приведу несколько строк кода, которые могут быть полезны для администрирования самого SCCM сервера.
Вот этим простейшим кодом вы можете получть пакетов, дистрибуция которых выполнилась не успешно на опредленном DP сервере (сайт-код положим CEN):
1 2 3 4 5 6 7 | Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" # Import the ConfigurationManager.psd1 module $SiteCode = "CEN" $SitePath = "CEN:" $primary_server = "prim_srv" $DP = Read-Host "Enter DP FQDN" $query = Get-WmiObject –NameSpace Root\SMS\Site_$SiteCode –Class SMS_DistributionDPStatus -ComputerName $primary_server -Filter "Name='$DP'" | where MessageState -NE '1'| Select PackageID, MessageID, MessageState, LastUpdateDate, ObjectTypeID |
Удалить контент определенного пакета со всех DP севреров:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process if((Get-Module ConfigurationManager) -eq $null) { Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" } # Set the current location to be the site code. Set-Location "CEN:\" $date = Get-Date $log = "c:\temp\remove_cmcontent_all_dp.txt" "" | Out-File $log -Append "==== $date ==== " | Out-File $log -Append $pkg = Read-Host "Enter PackageID" $query = Get-WmiObject –NameSpace Root\SMS\Site_CEN –Class SMS_DistributionDPStatus -ComputerName PRIM_SRV –Filter "PackageID='$pkg'" | Select Name, ObjectTypeID $ObjType = $query.ObjectTypeID $dplist = $query.Name if ($ObjType -eq "2") { "Package Type is Regular package" try { foreach ($DPname in $dplist) { Write-host "Working on package $pkg --> $DPname" -ForegroundColor Yellow "Working on package $pkg --> $DPname">>$log Remove-CMContentDistribution -DistributionPointName $DPname -Force -PackageId $pkg -ErrorAction Continue Write-host "Completed the package $pkg Removal from $DPname" -ForegroundColor green "Completed the package $pkg Removal from $DPname">>$log } } catch { #Catch the exception here Write-host "-Exeception error on $DPname. Check logFile more details" -ForegroundColor Red #Write the server name to $log "$pkg has thrown asn error $($_.exception)" >> $log } } if ($ObjType -eq "18") { "Package Type is OS Image" try { foreach ($DPname in $dplist) { Write-host "Working on package $pkg --> $DPname" -ForegroundColor Yellow "Working on package $pkg --> $DPname">>$log Remove-CMContentDistribution -DistributionPointName $DPname -Force -OperatingSystemImageId $pkg -ErrorAction Continue Write-host "Completed the package $pkg Removal from $DPname" -ForegroundColor green "Completed the package $pkg Removal from $DPname">>$log } } catch { #Catch the exception here Write-host "-Exeception error on $DPname. Check logFile more details" -ForegroundColor Red #Write the server name to $log "$pkg has thrown asn error $($_.exception)" >> $log } } if ($ObjType -eq "19") { "Package Type is Boot Image" try { foreach ($DPname in $dplist) { Write-host "Working on package $pkg --> $DPname" -ForegroundColor Yellow "Working on package $pkg --> $DPname">>$log Remove-CMContentDistribution -DistributionPointName $DPname -Force -BootImageId $pkg -ErrorAction Continue Write-host "Completed the package $pkg Removal from $DPname" -ForegroundColor green "Completed the package $pkg Removal from $DPname">>$log } } catch { #Catch the exception here Write-host "-Exeception error on $DPname. Check logFile more details" -ForegroundColor Red #Write the server name to $log "$pkg has thrown asn error $($_.exception)" >> $log } } if ($ObjType -eq "14") { "Package Type is OS Upgrade Package" try { foreach ($DPname in $dplist) { Write-host "Working on package $pkg --> $DPname" -ForegroundColor Yellow "Working on package $pkg --> $DPname">>$log Remove-CMContentDistribution -DistributionPointName $DPname -Force -OperatingSystemInstallerId $pkg -ErrorAction Continue Write-host "Completed the package $pkg Removal from $DPname" -ForegroundColor green "Completed the package $pkg Removal from $DPname">>$log } } catch { #Catch the exception here Write-host "-Exeception error on $DPname. Check logFile more details" -ForegroundColor Red #Write the server name to $log "$pkg has thrown asn error $($_.exception)" >> $log } } if ($ObjType -eq "23") { "Package Type is Driver Package" try { foreach ($DPname in $dplist) { Write-host "Working on package $pkg --> $DPname" -ForegroundColor Yellow "Working on package $pkg --> $DPname">>$log Remove-CMContentDistribution -DistributionPointName $DPname -Force -DriverPackageId $pkg -ErrorAction Continue Write-host "Completed the package $pkg Removal from $DPname" -ForegroundColor green "Completed the package $pkg Removal from $DPname">>$log } } catch { #Catch the exception here Write-host "-Exeception error on $DPname. Check logFile more details" -ForegroundColor Red #Write the server name to $log "$pkg has thrown an error $($_.exception)" >> $log } } |
Примеров использования Powershell для управления SCCM серверами и клиентом достаточно много, но все они основываются на использовании классов SMS, зарегистрированных при установке SCCM сервера, и WMI.