Right now I am working on a couple scripts that take data from a couple sources and tries to match them up. I have a working method but am trying to find out if there is a better way to do what I am trying to do.
What I am trying to do is match up a computer name from a CSV file with one from a SCCM SQL query. Right now the CSV has 8500ish lines while the SCCM query returns 13000ish. So, I am looping one hell of a lot to find that one PC name in the SCCM query. Is there a better / faster way to do that compare? Other than looping through the SCCM query multiple times?
#$SCCMPrimaryuser SQL query
(contains Computername, Primary user, last logged on user, timestamp)
$DPInfo = Import-Csv ".\DataProtector_AccountInfo.csv"
$output=@()
$DPInfo | % {
$dpIDdisplay = $_."DP ID display"
$dpID = $_."DP ID"
$dpDiplayName = $_."DP Displayname"
$dpComputer = $_."DP Computer Name"
$dpEmail = $_."DP email"
$dpLastBackup = $_."DP Date Last Backup"
$dpStatus = $_."DP Status"
$sccmllou = $null
$sccmllouT = $null
$sccmPrimUser = $null
$SCCMPrimaryuser | % {
If ($dpComputer -eq $_.ComputerName){
If ($_."Last Logged on User"){$sccmllou = $_."Last Logged on User"}else{$sccmllou = "n/a"}
If ($_."Last Login Time"){$sccmllouT = $_."Last Login Time"}else{$sccmllouT = "n/a"}
If ($_.PrimaryUser){$sccmPrimUser = $_.PrimaryUser}else{$sccmPrimUser = "n/a"}
}
}
$record = @{"Computer" = $dpComputer}
$record.add("DP Display ID",$dpIDdisplay)
$record.add("DP ID",$dpID)
$record.add("DP Email",$dpEmail)
$record.add("DP Last Backup",$dpLastBackup)
$record.add("DP DisplayName",$dpDiplayName)
$record.add("SCCM Primary User",$sccmPrimUser)
$record.add("DP Status",$dpStatus)
$record.add("SCCM last log user",$sccmllou)
$record.add("SCM Last log time",$sccmllouT)
New-Object PSObject -Property $record | out-null
$output+=New-Object PSObject -Property $record | Out-Null
}