Solved

home folder path for users

Posted on 2016-10-05
4
56 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
  • 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
A brief introduction to what I consider to be the best editor for PowerShell.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now