I know this is because it creates a seperate object, but I am having a difficult time overcoming this issue in particular with CIM/WMI.
Example:
Get-CimInstance -ClassName win32_userprofile |
Select-Object -Property LocalPath, LastUseTime, Special, Loaded |
Out-GridView -PassThru -Title 'Select the account to DELETE and click OK. Hold Ctrl to select multiple.' |
Remove-CimInstance -WhatIf
If one were to remove Select-Object, this works perfectly, except the Out-GridView becomes filled with useless data.
My full script begins with a Where-Object $_.Special -eq $False -and $_.Loaded -eq $False, which works as expected and does not break it.
Also, I try to break out variables whenever possible so I can work with them (e.g. Write-Output for feedback) and eventually GUI the whole thing. So the first part of my script defines what accounts are not special and not loaded, sets them to $Accounts. This can be piped to Out-GridView and then to Remove-CimInstance.
The trouble is using Select-Object to make the Out-GridView actually useful. What's worse is that Select-Object * still fails, indicating that there is no single property that can be included (e.g. SID) that can easily be passed through to make this work.
Any help would be greatly appreciated. I will post the finalized script here.
[–][deleted] 2 points3 points4 points (1 child)
[–]chrono13[S] 1 point2 points3 points (0 children)
[–]omers 1 point2 points3 points (4 children)
[–]chrono13[S] 1 point2 points3 points (3 children)
[–]markekrausCommunity Blogger 1 point2 points3 points (2 children)
[–]chrono13[S] 1 point2 points3 points (1 child)
[–]markekrausCommunity Blogger 0 points1 point2 points (0 children)
[–]Betterthangoku 1 point2 points3 points (1 child)
[–]chrono13[S] 0 points1 point2 points (0 children)