Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foreach($line in Get-Content .\users.txt) {
- $user_op = ""
- $user_op = net users $line /domain 2>NULL | select-string -pattern 'Home directory'
- if ($user_op -like '*Home directory*') {
- $line = echo $user_op | out-String #| %{ $_.split("\\")[2] }
- # echo $user_op.GetType() # matchInfo system.object
- # echo $line.GetType() # object[] system.array => string when not -Stream on out-string
- # substring
- $right = ""
- $post = $line.IndexOf("hq-ps-home")
- try {
- # $right = $line.Substring($post+1)
- #
- # $separator = "\\\\"
- # $parts = $line.split($separator)
- # $right = $parts[2]
- #
- # $line = [regex]::escape($line)
- #
- if ($line -match '\\([^\\]+)$') {
- # echo $line
- $right = $line.Substring($line.IndexOf('\') + 1)
- }
- }
- catch {
- Continue
- }
- #Write-Host '\'$right
- if ($right) {
- $right = $right -replace '\s',''
- write-host "\$right"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement