?
Solved

home folder path for users

Posted on 2016-10-05
4
Medium Priority
?
149 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 2000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Here's a look at newsworthy articles and community happenings during the last month.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

800 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