Trying to search all PC desktops for a certain shortcut

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? :slight_smile: 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,

Try it this way:

$computerList = 
    Get-ADComputer -Filter * -SearchBase "My_OU_locations" | 
        Select-Object -ExpandProperty Name
$Result = 
    foreach ($ComputerName in $computerList) {
        If (Test-Connection $ComputerName -count 1 -quiet) {
            Invoke-Command -ComputerName $ComputerName -ScriptBlock { 
                Get-ChildItem -Path C:\Users\*\Desktop\*myshortcuts*.lnk | 
                    Sort-Object PSComputerName -Descending 
            } | 
            Select-Object PSComputerName, Name 
        }
    } 

$Result | 
Out-GridView

That seemed to have more usable results. I guess I should not have had the out-gridview “inside” my squigglies.

Much appreciated