?
Solved

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

Posted on 2009-06-29
5
Medium Priority
?
1,161 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 2000 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 2000 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

Bringing Advanced Authentication to the SMB Market

WatchGuard announces the acquisition of advanced authentication provider, Datablink, with one mission – to bring secure authentication to SMB, mid-market, and distributed enterprises with a cloud-based solution, ideal for resale via their established channel & MSSP community.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

752 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