Advertisement
Eliel_Sec

PowerShell_Listar Nome_Ipv4_mac labin A - melhorado

Sep 13th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##Listar Nome, Endereço IP e Mac das maquinas do lab A melhorado
  2.  
  3.  
  4. $computers  = Get-Content C:\Users\eliel\Desktop\scritps_powershell\labin_a_pcs.txt
  5. $online = @()
  6. $offline = @()
  7. $credencial = Get-Credential Administrador
  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. $resultado = (Invoke-Command -ComputerName $online { Get-WmiObject -Class win32_networkadapterconfiguration | Where-Object index -EQ 7 | Select-Object pscomputername, ipaddress, macaddress } -Credential $credencial )
  27.  
  28.  
  29. $resultado | Select-Object pscomputername, ipaddress, macaddress | Sort-Object -Property PSComputerName | Format-Table | Out-File -FilePath C:\Users\eliel\Desktop\nomes_enderecos_mac.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement