简体   繁体   English

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

[英]script tuning for include all computers in domain

I have a script which scans given computers in domain for identifying and disables mobile hotspot function in windows 10. Script works properly , but i want to scan all my domain comupters, not only specified.. can anyone help me for adjusting this script? 我有一个脚本,该脚本可以扫描域中的给定计算机以识别并禁用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
    }
}

If you replace $computers = @("nr1", "nr2", "nr3") with something like: 如果将$computers = @("nr1", "nr2", "nr3")替换为以下内容:

Import-Module ActiveDirectory
$computers = Get-ADComputer -Properties DNSHostName

That should return an array of hostnames. 那应该返回一个主机名数组。 You may need to provide credentials via -Credential , and you can -Filter the results if you need to exclude any machines. 您可能需要通过-Credential提供凭据,如果需要排除任何计算机,则可以-Filter结果。

See docs and examples of Get-ADComputer here . 在此处查看文档和Get-ADComputer示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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