Solved

home folder path for users

Posted on 2016-10-05
4
108 Views
Last Modified: 2016-10-06
dear experts

I'm working on this script and partly working but it pulls AD accounts that is not in csv file

What I would like to have is the  home drive path for given users in csv file. Could you help me with this please?
csv file has colun header "SamAccountNAme" and users are listed as Mike.Beach (firstname.Surname)

import-module activedirectory
$list =import-csv "H:\temp\userlist.csv"
ForEach ($User in $UserList)
{Get-Aduser -Filter * -properties Name,homedirectory,homedrive |export-csv -path H:\temp\export\result.csv}
0
Comment
Question by:kuzum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41830666
There are few issues with code, example.. You are using command Get-Aduser -Filter * inside the Foreach loop, which will output all users in Activedirectory, another problem, you are saving user list in to variable $list but uses different variable with Foreach loop ( ForEach ($User in $UserList) ).. etc..
Try this code..
import-module activedirectory
Import-csv "H:\temp\userlist.csv" | ForEach {Get-Aduser $_.SamAccountNAme -properties Name,homedirectory,homedrive} |export-csv -path H:\temp\export\result.csv

Open in new window


If you want to correct your code...
Import-module activedirectory
$list =import-csv "H:\temp\userlist.csv" 
$(ForEach ($User in $list) {
 Get-Aduser $User.SamAccountNAme -properties Name,homedirectory,homedrive
}) | Export-csv -path H:\temp\export\result.csv

Open in new window

0
 

Author Comment

by:kuzum
ID: 41830827
EXCELLENT! it did the job I needed. I will have another question please on a separate thread if you could help please?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41830925
Sure.. post the link to question.. and don't forget to close this question.. :-)
0
 

Author Closing Comment

by:kuzum
ID: 41832699
excellent result!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question