Guest User

Untitled

a guest
Nov 25th, 2018
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. $username = "domainadministrator"
  2. $password = "Your password"
  3. $credential = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password
  4. $computers = Get-ADComputer -Filter *
  5. foreach($computer in $computers){
  6. $computerDNS = $computer.DNSHostName
  7. $hotspot = Invoke-Command -ComputerName $computerDNS -credential $credential -scriptblock {
  8. $hotspot = Get-Service "icssvc"
  9. if($hotspot.Status -eq "Running"){
  10. Write-Host "Hotspot is turned on on $env:computername" -ForegroundColor Red
  11. try{
  12. Start-Service "icssvc"
  13. Write-Host "Successfully stopped service on $env:computername" -ForegroundColor Green
  14. }catch{
  15. Write-Host "Unable to stop service on $env:computername" -ForegroundColor Red
  16. }
  17. }else{
  18. Write-Host "No Hotspot running on $env:computername" -ForegroundColor Green
  19. }
  20. }
  21. }
Add Comment
Please, Sign In to add comment