Powershell unable to display or export results in a form

Gareth Davies 55 Reputation points
2024-02-07T21:06:21.4633333+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()

} 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

Windows for business Windows Server User experience PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-02-08T07:01:38.04+00:00

    Hi Gareth Davies,

    According to the error message, it seems the pipeline operators "|" before Out-String and Export-Csv are missing for some reason.

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

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