Advertisement
Eliel_Sec

PowerShell_Apagar_usuario_local

Jun 6th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##apagar um usuário local em todas as maquinas
  2.  
  3. #variaveis
  4. $credencial = Get-Credential Administrador
  5. $computers = Get-Content C:\Users\eliel\Desktop\labin_a_pcs.txt
  6. $online = @()
  7. $offline = @()
  8. $contador = 1
  9.  
  10. #repetir enquanto $contador <= 5, faz o processo 5 vezes
  11. DO{
  12.  
  13. Foreach($pc in $computers) {
  14.     if (Test-Connection -BufferSize 32 -Count 1 -ComputerName $pc -Quiet ) {
  15.  
  16.          if (Test-WSMan -ComputerName $pc -ErrorAction SilentlyContinue ) {  $online += $pc }
  17.          
  18.         else  { $offline += $pc }
  19.        
  20.  
  21. }
  22.  
  23. else { $offline += $pc }
  24.  
  25. }
  26.  
  27. # Exibe e conta o numero de pcs
  28. Write-Output "O comando sera executado nos seguintes computadores: " $online
  29. Write-Output "Total de computadores ligados: " $online.Count
  30.  
  31. #deleta o usuario que vc especificar em frente o user
  32. Invoke-Command -ComputerName $online { net user nerd /DELETE } -Credential $credencial
  33.  
  34. #zera o conteudo da variavel e add 1 ao contador
  35. $online.Clear() ; $online = @()
  36. $contador++
  37.  
  38. } while ( $contador -le 3 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement