Solved

home folder path for users

Posted on 2016-10-05
4
46 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sure.. post the link to question.. and don't forget to close this question.. :-)
0
 

Author Closing Comment

by:kuzum
Comment Utility
excellent result!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 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

12 Experts available now in Live!

Get 1:1 Help Now