Solved

home folder path for users

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
In-place Upgrading Dirsync to Azure AD Connect
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.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

856 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