Powershell 用于包含域中所有计算机的脚本调整

Powershell 用于包含域中所有计算机的脚本调整,powershell,Powershell,我有一个脚本,可以扫描域中给定的计算机,以识别和禁用Windows10中的移动热点功能。脚本工作正常,但我想扫描所有域计算机,而不仅仅是指定的。。有人能帮我调整这个脚本吗 $username = "domain\administrator" $password = "Your password" $credential = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password

我有一个脚本,可以扫描域中给定的计算机,以识别和禁用Windows10中的移动热点功能。脚本工作正常,但我想扫描所有域计算机,而不仅仅是指定的。。有人能帮我调整这个脚本吗

$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
过滤结果


请参阅
获取ADComputer

的文档和示例。您已经尝试获取域中的所有计算机了吗?请查看