Hello all.
So, here is my mission.
- Create a script for all Windows 7/Windows 8 workstations to audit connected network drives, output to CSV and save out to a network share…Done
- Deploy this script to a few thousand workstations…Done
- Take all csv files and combine into one master sheet…Done
- Add FirstName,LastName,Email to master csv based on their network ID that was found during the audit…
This is where my problem comes in. I have a working solution to add the data but it will take days of hitting AD for each user (and 90% of these users are shown multiple times if they have multiple drives mapped.)
EXAMPLE: MASTER.CSV
Computer UserID Date DeviceID ProviderName DriveType
Computer1234 djones 10/8/2014 12:00 H: \someserver\path\junk Network Drive
Computer1234 djones 10/8/2014 12:00 F: \someserver\path\otherjunk Network Drive
Computer1235 jsnover 10/8/2014 12:00 G: \server\unc Network Drive
Computer1288 bgates 10/8/2014 12:00 H: \server12\unc Network Drive
EXAMPLE: Desired result
Computer UserID FirstName LastName Email CostCenter Date DeviceID ProviderName DriveType
Computer1234 djones Don Jones djones@abc.com 123456 10/8/2014 12:00 H: \someserver\path\junk Network Drive
Computer1234 djones Don Jones djones@abc.com 123456 10/8/2014 12:00 F: \someserver\path\otherjunk Network Drive
Computer1235 jsnover Jeff Snover jsnover@abc.com 234567 10/8/2014 12:00 G: \server\unc Network Drive
Computer1288 bgates Bill Gates bgates@abc.com 918456 10/8/2014 12:00 H: \server12\unc Network Drive
If I use something like
$csv= "c:\somefolder\master.csv"
Import-CSV $csv | select 'Computer','UserID',`
@{ n = 'FirstName'; e = { ((Get-Qaduser $_.UserID).FirstName) } },`
@{ n = 'LastName'; e = { ((Get-Qaduser $_.UserID).LastName) } },`
@{ n = 'Email'; e = { ((Get-Qaduser $_.UserID).Email) } },`
@{ n = 'Cost Center'; e = { ((Get-Qaduser $_.UserID).physicalDeliveryOfficeName) } },`
'Date',`
'DeviceID',`
'ProviderName',`
'DriveType' | Export-CSV -Path "C:\somefolder\master_final.csv" -NoTypeInformation
I get results correctly but my kids will have graduated college by the time it’s finished. I’ve thought of a couple ways to do this with something like -unique and pulling that into an array but there has to be a better way.
Thanks everyone
PG