Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1.  
  2. foreach($line in Get-Content .\users.txt) {
  3. $user_op = ""
  4.  
  5. $user_op = net users $line /domain 2>NULL | select-string -pattern 'Home directory'
  6.  
  7. if ($user_op -like '*Home directory*') {
  8. $line = echo $user_op | out-String #| %{ $_.split("\\")[2] }
  9. # echo $user_op.GetType() # matchInfo system.object
  10. # echo $line.GetType() # object[] system.array => string when not -Stream on out-string
  11.  
  12. # substring
  13. $right = ""
  14. $post = $line.IndexOf("hq-ps-home")
  15. try {
  16. # $right = $line.Substring($post+1)
  17. #
  18. # $separator = "\\\\"
  19. # $parts = $line.split($separator)
  20. # $right = $parts[2]
  21. #
  22. # $line = [regex]::escape($line)
  23. #
  24. if ($line -match '\\([^\\]+)$') {
  25. # echo $line
  26. $right = $line.Substring($line.IndexOf('\') + 1)
  27. }
  28.  
  29. }
  30. catch {
  31. Continue
  32. }
  33. #Write-Host '\'$right
  34. if ($right) {
  35. $right = $right -replace '\s',''
  36. write-host "\$right"
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement