Link to home
Start Free TrialLog in
Avatar of brianroma
brianroma

asked on

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

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...
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brianroma
brianroma

ASKER

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>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK that works great!

Thanks!

Brian

Sorted with deleting the folders afterwards?

Chris