Ignore question, Code blocks are messed up and it will not let me delete the question or edit it to make any sense.
Powershell error when trying to display or export
Gareth Davies
55
Reputation points
I am trying to create a form to display or output accounts are not in 2 specific OUs and have not logged on for 30 days or more. If I run the code in native powershell or ISE it works, but when I import it to the form and target the output window to display or try to run the export-csv cmdlet it gives me an error. The 2 scripts each run on a button press, code for the display button is <{
$InactiveDays = 30
Get-ADUser -Filter { LastLogonTimeStamp -lt $Days -and enabled -eq $true } -SearchBase 'DC=company,DC=LOCAL' -Properties LastLogonTimeStamp | Where-Object { ($_.DistinguishedName -notlike "*OU=OU,OU=OU2,DC=company,DC=local") } | Where-Object { ($_.DistinguishedName -notlike "*OU=OU3,OU=OU4,OU=OU5,DC=company,DC=local") } |
select-object Name, @{ Name = "Date"; Expression = { [DateTime]::FromFileTime($_.lastLogonTimestamp).ToString('MM-dd-yyyy') } } | Out-String $GroupListView.Focus()
}>