Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. read-host -assecurestring | convertfrom-securestring | out-file C:\Temp\mysecurestring.txt
  2.  
  3. Get-ADComputer -Filter 'Name -like "COMPUTERNAME"' -Properties * | ForEach-Object {
  4. $comp1 = $_.name
  5. $username = "$comp1\Administrator"
  6. $password = cat C:\Temp\mysecurestring.txt | convertto-securestring
  7. $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
  8.  
  9. Invoke-Command -ComputerName $comp1 -Cred $cred -Scriptblock {
  10. $usersChild = Get-ChildItem -Path "C:\Users" | Where { $_.Name -like 'USERNAME*'}
  11.  
  12. Write-Verbose "Additional Directory Cleanup - Removing $($usersChild.Name) on $env:COMPUTERNAME..."
  13.  
  14. Remove-Item -Path $($usersChild.FullName) -Recurse -Force -ErrorAction Stop
  15.  
  16. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement