I have a couple different shortcuts on some computers and I need to find out who has them. I don’t want to just remove them from everywhere as some still need it, but I don’t know who all those users are at the moment. Just messing around, I came up with the below as gci seems to be the best starting point. When I run the below, it opens the out-gridview in hundreds of windows. I’d like it all in 1 window if possible. I have also tried to maybe export-csv to a single file but doesn’t seem to populate the file. Any pointers as to what I am doing wrong? Maybe I should not be using invoke-command??
Get-ADComputer -Filter * -SearchBase "My_OU_locations" | ForEach-Object {$_.Name} | Out-File My_pc_outputfile.txt
$computers = Get-Content My_pc_outputfile.txt
foreach($computer in $computers){
If (Test-Connection $computer -count 1 -quiet) {
Write-Output $computer
Invoke-Command -ComputerName $computer -ScriptBlock {Get-ChildItem -Path C:\Users\*\Desktop\*myshortcuts*.lnk | Sort-Object PSComputerName -Descending} | Select-Object PSComputerName, Name | Out-GridView
}
}
Regards,