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()
}
Using this I get the error
Select-Object : A positional parameter cannot be found that accepts argument 'Out-String'.
The export script is
{
$InactiveDays = 30
$Days = (Get-Date).Adddays(-($InactiveDays))
powershell
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') } } | export-csv c:\30days.csv
}
This gives me
Select-Object : A positional parameter cannot be found that accepts argument 'Export-Csv'.
What am I missing here? I have used this code in other forms without issue but this time it says it doesn't understand pretty basic commands