繁体   English   中英

脚本调优以包括域中的所有计算机

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM