Advertisement
Eliel_Sec

PowerShell_Listar Nome_Ipv4_mac labin C - melhorado

Sep 19th, 2017
112
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 C - Melhorado
  2.  
  3.  
  4. $credencial = Get-Credential Administrador
  5. $computers  = Get-Content C:\Users\eliel\Desktop\scritps_powershell\labin_c_pcs.txt
  6. $online = @()
  7. $offline = @()
  8.  
  9.  
  10. Foreach($pc in $computers) {
  11.     if (Test-Connection -BufferSize 32 -Count 1 -ComputerName $pc -Quiet) {
  12.  
  13.          if (Test-WSMan -ComputerName $pc ) {  $online += $pc }
  14.          
  15.          else  { $offline += $pc }
  16.  
  17. }
  18.  
  19. else { $offline += $pc }
  20.  
  21. }
  22.  
  23. Write-Output "O comando sera executado nos seguintes computadores: " $online
  24. Write-Output "Total de computadores ligados: " $online.Count
  25.  
  26.  
  27. $resultado = (Invoke-Command -ComputerName $online { Get-WmiObject -Class win32_networkadapterconfiguration | Where-Object DNSDomain -eq -value "10.40.3.250" | Select-Object pscomputername, ipaddress, macaddress } -Credential $credencial )
  28.  
  29. $resultado | Select-Object pscomputername, ipaddress, macaddress | Sort-Object -Property PSComputerName | Format-Table | Out-File -FilePath C:\Users\eliel\Desktop\nomes_enderecos_mac_labinc.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement