Share via

Powershell error when trying to display or export

Gareth Davies 55 Reputation points
2024-02-07T20:53:32.0833333+00:00

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()
}>

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Gareth Davies 55 Reputation points
    2024-02-07T21:01:39.8766667+00:00

    Ignore question, Code blocks are messed up and it will not let me delete the question or edit it to make any sense.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.