listpowershellactive-directory

Powershell command using list as variable


I am trying to write a script to look at users and what AD groups they are part of, looking for a specific group that has multiple "sub groups". example VPN-GRP-ONE, VPN-GRP-TWO, VPN-GRP-THREE....

tried using some stuff I found on a few demos but its not working right as it wants the ActiveDirectory module imported to use get-aduser and we are not allowed to install new modules we dont already have. (I dont have ActiveDirectory in my available modules)

I was trying to use:

$list1 = C:\Users\MrAoxx\Documents\List1.txt
foreach ($_ in $list1) {
net user $_ /domain}

I was hoping for ouput that I could then take the next step to piping that to a new text file and begin stripping what I needed out of it to get just the AD group names I was looking for ie: ONE, TWO, THREE. But all its doing is opening the txt file and nothing else.


Solution

  • $list1 = get-content 'C:\Users\MrAoxx\Documents\List1.txt'
    foreach ($_ in $list1) {
    net user $_ /domain >> C:\Users\MrAoxx\Documents\FullList.txt} 
    

    This worked the way I needed it to, thanks to @LotPings for the answer.