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,152 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
  • 3
  • 2
5 Comments
 
LVL 70

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 70

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 70

Expert Comment

by:Chris Dent
ID: 24736568

Sorted with deleting the folders afterwards?

Chris
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

19 Experts available now in Live!

Get 1:1 Help Now