[英]Powershell script to send WoL via SCCM
我希望將一個簡短的 Powershell 腳本放在一起,詢問資產編號,然后通過 Config Manager/SCCM 向該資產發送 WoL 請求以將其喚醒。 我見過的大多數 Powershell WoL 腳本似乎在沒有 SCCM 的情況下實現了這一點,通過創建通過 mac 地址發送它們的魔法數據包——我不想這樣做。
我在網上搜索,看看是否有人已經做到了這一點,並看到了這個頁面:
在該頁面上,他們展示了由 Johan Schrewelius 和 Jörgen Nilsson 編寫的腳本,其中包含以下內容:
[CmdletBinding()]
Param(
$CmpName = $Null,
$CollId = "SMS00001",
$SiteServer = "<site server fgdn>"
)
if (!$CmpName -and $CollId -eq "SMS00001") {
Write-Host "Seems wrong to wake every single computer in the environment, refusing to perform."
exit 1
}
$SiteCode = (Get-WmiObject -ComputerName "$SiteServer" -Namespace root\sms -Query 'SELECT SiteCode FROM SMS_ProviderLocation').SiteCode
if ($CmpName) {
$ResourceID = (Get-WmiObject -ComputerName "$SiteServer" -Namespace "Root\SMS\Site_$($SiteCode)" -Query "Select ResourceID from SMS_R_System Where NetBiosName = '$($CmpName)'").ResourceID
if ($ResourceID) {
$CmpName = @($ResourceID)
}
}
$WMIConnection = [WMICLASS]"\\$SiteServer\Root\SMS\Site_$($SiteCode):SMS_SleepServer"
$Params = $WMIConnection.psbase.GetMethodParameters("MachinesToWakeup")
$Params.MachineIDs = $CmpName
$Params.CollectionID = $CollId
$return = $WMIConnection.psbase.InvokeMethod("MachinesToWakeup", $Params, $Null)
if (!$return) {
Write-Host "No machines are online to wake up selected devices"
}
if ($return.numsleepers -ge 1) {
Write-Host "The resource selected are scheduled to wake-up as soon as possible"
}
可以通過將文件保存為類似 wol.ps1 的文件來運行此腳本,然后將$SiteServer變量設置為 SCCM FQDN,然后運行.\wol.ps1 -CmpName 'asset number'
以將 WoL 請求發送到單個資產,或者.\wol.ps1 -CmpName 'SCCM collection ID'
將 WoL 請求發送到 SCCM 資產集合。
這已經很不錯了,但我正在尋找的是一個基本的Read-Host
腳本,它請求一個資產編號,然后將 WoL 請求發送到該資產,僅此而已。 我已經嘗試拆除此腳本中的參數以獲得實現此目的所需的最少部分,但除了它從 SCCM 服務器請求的信息和請求資產的 SCCM 資源 ID 之外,我無法理解它,我不太明白它是如何工作的。
我可能最終會弄清楚,但我想我會把它扔在這里,看看是否有人以前做過這個,或者是否有人可以看到這個腳本是如何實現它的功能的,並且可以幫助我將它轉化為一個簡單的用戶輸入后的一系列簡短操作。
提前干杯。
Param(
$SiteServer = "Your SCCM Server"
)
$CmpName = Read-host "Enter asset number"
$SiteCode = (Get-WmiObject -ComputerName "$SiteServer" -Namespace root\sms -Query 'SELECT SiteCode FROM SMS_ProviderLocation').SiteCode
if ($CmpName) {
$ResourceID = (Get-WmiObject -ComputerName "$SiteServer" -Namespace "Root\SMS\Site_$($SiteCode)" -Query "Select ResourceID from SMS_R_System Where NetBiosName = '$($CmpName)'").ResourceID
if ($ResourceID) {
$CmpName= @($ResourceID)
}
}
$WMIConnection = [WMICLASS]"\\$SiteServer\Root\SMS\Site_$($SiteCode):SMS_SleepServer"
$Params = $WMIConnection.psbase.GetMethodParameters("MachinesToWakeup")
$Params.MachineIDs = $CmpName
$return = $WMIConnection.psbase.InvokeMethod("MachinesToWakeup", $Params, $Null)
if (!$return) {
Write-Host "No machines are online to wake up selected devices"
}
if ($return.numsleepers -ge 1) {
Write-Host "The resource selected are scheduled to wake-up as soon as possible"
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.