So, there are a couple of things that I’m struggling with here.
I have a list of user ids. I also have a list of AD users. I’m comparing the two and looking for matches.
CSV 1
Filename,UserID
something.txt,user1
CSV 2
UserID,FirstName,LastName,Email
user1,User, 1, user1@email.com
I want to compare the UserID column in csv 1 with the userid column in csv 2 (or vice versa).
My end result would look like this…
UserID,FirstName,LastName,Email,Match
user1,user,1,user1@email.com,TRUE
Where the Match column would be the $_.sideindicator translated into a Boolean.
Here is what I have and it seems to “look” like it is doing what I want but some information is not making it too the final product.
$yearbook = Get-ChildItem “\servername\highschool\yearbook” -Force | where {$.PSIsContainer -eq $false -and $.Name -like “*.jpg”}
$pics = @()
Foreach ($pic in $yearbook)
{
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name FileName -Value $pic.Name
$obj | Add-Member -MemberType NoteProperty -Name UserID -Value $pic.BaseName
$pics += $obj
}
$Pics | export-csv -Path “$PSScriptRoot\temppics.csv”
$CSV = “$PSScriptRoot\temppics.csv”
$userTable = @{}
filter UpdateUserTable
{
$userTable[$.SamAccountName] = [pscustomobject] @{
FirstName = $.FirstName
LastName = $.LastName
Email = $.Email
}
}
$userTable = Get-QADUser -SizeLimit 0 | Where { ($_.type -eq “user”) | UpdateUserTable
$userdump = @()
Foreach ($user in $userTable)
{
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name UserID -Value $user.SamaccountName
$obj | Add-Member -MemberType NoteProperty -Name ‘First Name’ -Value $user.FirstName
$obj | Add-Member -MemberType NoteProperty -Name ‘Last Name’ -Value $user.LastName
$obj | Add-Member -MemberType NoteProperty -Name ‘E-Mail’ -Value $user.Email
$userdump += $obj
}
$userdump | export-csv -Path “$PSScriptRoot\tempad.csv”
$file1 = import-csv -Path “$psscriptroot\tempad.csv”
$file2 = import-csv -Path “$psscriptroot\temppics.csv”
$compare = Compare-Object $file1 $file2 -property UserID -IncludeEqual
$compare | Export-Csv -Path “$psscriptroot\final.csv” -NoTypeInformation
$csv= ‘c:\somefolder\master.csv’
$userTable = @{}
filter UpdateObject
{
$csvEntry = $_
$userEntry = $userTable[$csvEntry.UserID]
[pscustomobject] @{
UserID = $csvEntry.UserID
FirstName = $user.FirstName
LastName = $user.LastName
Email = $user.Email
Bool = $record.SideIndicator
}
}
Import-Csv “$psscriptroot\final.csv” |
UpdateObject |
Export-Csv -Path “$psscriptroot\final1.csv” -NoTypeInformation