Help Compare Sideindicator script not populating information

Hello,

I had this working on another script but today it is not working on a new script i have been developing to compare information from one CSV to another. It is working past the compare-object. But when It goes through the foreach it is breaking and not transfering the data over to the removed Removed or Added Varables leaving the data blank.

Examples and script info below

Issue after foreach

Name :

SamAccountName :

Description :

Enabled :

PasswordLastSet :

Created :

LastLogon :

Script

$CSVGetNEWENTADMIN = ".DoNotTouchDomainAccountAdminsGetENTADMIN.csv" $CHKENTADMIN = Import-Csv -Path $CSVGetNEWENTADMIN $GetENTADMIN = Get-ADGroup 'CN=Enterprise Admins,OU=,OU=,DC=DC=com' -Properties Member | Select-Object -ExpandProperty Member | ForEach-Object{Get-ADuser $_ -Properties Name, SamAccountName, Description,Enabled, PasswordLastSet, lastLogon, Created, l} | Select Name, SamAccountName, Description,Enabled, PasswordLastSet, Created, @{n='LastLogon';e={[datetime]::FromFileTime($_.lastLogon).ToString('yyyy-MM-dd HH:mm:ss.fff')}} $ComparedENTADMIN = Compare-Object -ReferenceObject $CHKENTADMIN -DifferenceObject $GetENTADMIN foreach ($Name in $ComparedENTADMIN) { if ($Name.SideIndicator -eq "=>") { $NewObject = [PSCustomObject] @{ Name = $Name.Name SamAccountName = $Name.SamAccountName Description = $Name.Description Enabled = $Name.Enabled PasswordLastSet = $Name.PasswordLastSet Created = $Name.Created LastLogon = $Name.LastLogon } $AddedENTADMIN += $NewObject } if ($Name.SideIndicator -eq "<=") { $NewObject = [PSCustomObject] @{ Name = $Name.Name SamAccountName = $Name.SamAccountName Description = $Name.Description Enabled = $Name.Enabled PasswordLastSet = $Name.PasswordLastSet Created = $Name.Created LastLogon = $Name.LastLogon } $RemovedENTADMIN += $NewObject } } 

submitted by /u/TheNaturalPhenomenon
[link] [comments]

Leave a Reply