0

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?

$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 } } 
2
  • 2
    What have you already tried to obtain all computers in a domain? Commented Nov 25, 2018 at 12:21
  • 2
    Have a look at Get-ADComputer Commented Nov 25, 2018 at 15:26

1 Answer 1

1

If you replace $computers = @("nr1", "nr2", "nr3") with something like:

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.

See docs and examples of Get-ADComputer here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.