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,159 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

Is Your AD Toolbox Looking More Like a Toybox?

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

717 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