powershell – Use hashtable as parameter when splatting

Hi,

When attempting to run below script then its returning null values description attribute.

$cutoff = (get-date).AddDays(-60) $querySplat = @{ "Filter" = {LastLogonDate -lt $cutoff -and Enabled -eq $True} "SearchBase" = "OU=Consultants,DC=contoso,DC=com" "Properties" = "lastlogon" ,"Description" } $userLogonsHash = @{} Get-ADDomainController -Filter * | Select-Object -ExpandProperty hostname | sort | foreach { $dc = $_ Write-Host $dc try { Get-ADUser -Server $dc @querySplat | foreach { $userId = $_.samaccountname.ToLower() if ($userLogonsHash.ContainsKey($userId) -eq $false) { $userLogonsHash.Add($userId,0) } if ($userLogonsHash[$userId] -lt $_.lastlogon) { $userLogonsHash[$userId] = $_.lastlogon } } } catch { Write-Warning ('Unable to query {0}: {1}' -f $dc,$_.exception.message) } } $userLogonsHash.GetEnumerator() | sort Name | Select-Object Description,@{n='UserId';e={$_.Name}},@{n='LastRealLogon';e={[datetime]::FromFileTime($_.Value)}} | Export-Csv -NoTypeInformation -Path C:exportConsultant_lastlogontime.csv -Encoding UTF8 

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

Leave a Reply