Advertisement
Eliel_Sec

PowerShell_Listar Hosts Online

Aug 29th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##Obter quais maquinas estão online na rede e com WinRM escutando.
  2.  
  3. ##altere a lista conforme o laboratório
  4. $computers = Get-Content C:\Users\eliel\Desktop\scritps_powershell\labin_c_pcs.txt
  5. $credencial = Get-Credential Administrador
  6. $online = @()
  7. $offline = @()
  8.  
  9. Foreach($pc in $computers) {
  10.     if (Test-Connection -BufferSize 32 -Count 1 -ComputerName $pc -Quiet) {
  11.  
  12.          if (Test-WSMan -ComputerName $pc ) {  $online += $pc }
  13.          
  14.          else  { $offline += $pc }
  15.  
  16. }
  17.  
  18. else { $offline += $pc }
  19.  
  20. }
  21.  
  22. Write-Output "O comando sera executado nos seguintes computadores: " $online
  23. Write-Output "Total de computadores ligados: " $online.Count
  24.  
  25.  
  26. ## use o invoke comand para executar o comando desejado nas maquinas online, ex:
  27. ##Invoke-Command -ComputerName $online { hostname; Get-Service -Name 'OCS Inventory Service', icas  | Format-Table -AutoSize } -Credential $credencial
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement