[英]Powershell script to run on all computers in domain - wait until computer is online
[英]script tuning for include all computers in domain
我有一個腳本,該腳本可以掃描域中的給定計算機以識別並禁用Windows 10中的移動熱點功能。腳本可以正常工作,但是我想掃描我所有的域計算機,而不僅僅是指定的計算機。有人可以幫助我調整此腳本嗎?
$username = "domain\administrator"
$password = "Your password"
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password
$computers = @("nr1", "nr2", "nr3")
foreach($computer in $computers){
$hotspot = Invoke-Command -ComputerName $computer -credential $credential -scriptblock {
$hotspot = Get-Service "icssvc"
if($hotspot.Status -eq "Running"){
Write-Host "Hotspot is turned on on $computer" -ForegroundColor Red
try{
Stop-Service "icssvc"
Write-Host "Successfully stopped service on $computer" -ForegroundColor Green
}catch{
Write-Host "Unable to stop service on $computer" -ForegroundColor Red
}
}else{
Write-Host "No Hotspot running on $computer" -ForegroundColor Green
}
}
如果將$computers = @("nr1", "nr2", "nr3")
替換為以下內容:
Import-Module ActiveDirectory
$computers = Get-ADComputer -Properties DNSHostName
那應該返回一個主機名數組。 您可能需要通過-Credential
提供憑據,如果需要排除任何計算機,則可以-Filter
結果。
請在此處查看文檔和Get-ADComputer
示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.