Jump to content

Hey all,

 

I'm relatively new to powershell, i figured out how i can export the home dirrectorys for a username I have it a text file.

 

get-aduser -identity (get-content c:\demo\users.txt) -properties homedirectory | out-file C:\demo\home.txt'

 

Only issue is -identity only lets you use one username not multiple

 

I will have to change to get-aduser -filter and filter by samaccountname i believe but unable to get it to work, any help would be awesome :D

Link to comment
https://linustechtips.com/topic/341749-powershell-get-aduser-issue/
Share on other sites

Link to post
Share on other sites

You could try something like this...

## Output user directories$Source = Get-Content $args[0]$OutFile = Get-Content $args[1]Foreach ($User in $Source){	Get-AdUser -Identity $User -Properties HomeDirectory | Out-File $OutFile}

I'm too lazy to check it against an AD right now, but I believe it should work. 

 

save it as a ps1 and call it "script C:\path\to\users.txt C:\path\to\outfile.txt"

Link to post
Share on other sites

Hey all,

 

I'm relatively new to powershell, i figured out how i can export the home dirrectorys for a username I have it a text file.

 

get-aduser -identity (get-content c:\demo\users.txt) -properties homedirectory | out-file C:\demo\home.txt'

 

Only issue is -identity only lets you use one username not multiple

 

I will have to change to get-aduser -filter and filter by samaccountname i believe but unable to get it to work, any help would be awesome :D

 

Try:

cat users.txt | Get-Aduser -Properties HomeDirectory > C:\demo\home.txt

or (if the Get-AdUser does not properly read those users from the pipeline)

cat users.txt | %{Get-Aduser -identity $_ -Properties HomeDirectory} > C:\demo\home.tx

I do not have an AD right now to test it, but it won't be hard

Link to post
Share on other sites

According to technet:

https://technet.microsoft.com/en-us/library/ee617241.aspx?f=255&MSPPError=-2147217396

Accept Pipeline Input?

true (ByValue)

pipelineInput

The Identity parameter is accepted from the pipeline, so the first option:

cat users.txt | Get-Aduser -Properties HomeDirectory > C:\demo\home.txt

 

Should work. You can even try something like:

cat users.txt | Get-Aduser -Properties HomeDirectory | select Identity,HomeDirectory | epcsv -Encoding UTF8 -Delimiter ';' -NoTypeInfo -Path C:\demo\users.csv 

To have a nice csv ready to be opened with Excel, or:

cat users.txt | Get-Aduser -Properties HomeDirectory | select Identity,HomeDirectory | ogv

For a nice window 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×