Solved

PowerShell Script that References CSV User list and checks for domain memebership and Exports results to csv

Posted on 2009-06-29
5
1,157 Views
Last Modified: 2012-05-07
Hey guys I have another challenge...

we have a csv list of user accounts from a directory list of roaming profile folders. We want to delete some of the folders but our management wants confirmation that there aren't Active Directory accounts associated with the folders.

Is there a way to script PowerShell to look at a csv (that has a list of names of old roaming profile folders) file, query AD if each item in the list is a user account, and if the item in the first csv is not an AD user account, then write to a second csv?

We can then take the second csv and delete the orphan roaming profile folders on our file server.

Thanks for your help...
0
Comment
Question by:brianroma
[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
  • 3
  • 2
5 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 24735766

If you were to deal with the first requirement first, something like this should work:

Import-CSV "OldFolders" | %{ If ((Get-QADUser $_.FolderName) -eq $Null) { $_ } } | Export-CSV "NoADAccount.csv"

I'm assuming you have the Quest AD CmdLets :) And assuming that your input CSV file contains a column named "FolderName".

Once that bit done the second requirements is dead easy :)

Chris
0
 

Author Comment

by:brianroma
ID: 24736106
I do have the Quest cmdlets installed.
I added "FolderName" at the top of the OldFolders.csv (snippet below):

FolderName
A1017230
acsbackup
administrator
Archive (Tom)
BPCopy

The NoADAccount.csv is created when the script runs, but it's empty.


I am getting this Error

Import-Csv : Cannot open file C:\PowerShell-Brian\Working Scripts\Checks List and Reports if User Exists in AD\OldFolders.
At C:\Users\myAccount\AppData\Local\Temp\3\00cee445-f6a5-4827-ab5e-4596a699fe9c.ps1:1 char:11
+ Import-CSV  <<<< "OldFolders" | %{ If ((Get-QADUser $_.FolderName) -eq $Null) { $_ } } | Export-CSV "NoADAccount.csv"
PS C:\PowerShell-Brian\Working Scripts\Checks List and Reports if User Exists in AD>
0
 
LVL 71

Assisted Solution

by:Chris Dent
Chris Dent earned 500 total points
ID: 24736134

OldFolders should have been the file name, sorry I didn't make that clear.

So something like:

Import-CSV "CurrentFileName.csv" | %{ If ((Get-QADUser $_.FolderName) -eq $Null) { $_ } } | Export-CSV "NoADAccount.csv"

Chris
0
 

Author Comment

by:brianroma
ID: 24736561
OK that works great!

Thanks!

Brian
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 24736568

Sorted with deleting the folders afterwards?

Chris
0

Featured Post

Are your AD admin tools letting you down?

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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