Problem with DNSHostName in invoke-command

Michał Klinowski 1 Reputation point
2022-04-20T15:26:06.73+00:00

Hi

I have problem with invoke-command

Problem with DNSHostName in invoke-command I would like that this command:

$DisplayName = 'SolarWinds '
$Publisher = 'Microsof'

 Get-ADComputer -Filter * | Select-Object -Property DNSHostName | format-list | Out-File C:\scripts\DNSHostName.txt

 Get-Content C:\scripts\DNSHostName.txt

Invoke-Command -ComputerName (Get-Content C:\scripts\DNSHostName.txt)  -ScriptBlock { Param($DisplayName,$Publisher)

Get-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |

 Where { $_.DisplayName -ne $null } |

  select  DisplayName,Publisher,DisplayVersion,InstallDate |

   Sort DisplayName |

    Where {$_.DisplayName -like "*$DisplayName*" -or $_.Publisher -like "*$Publisher*" }

    } -ArgumentList $DisplayName,$Publisher 

Get-Content C:\scripts\DNSHostName.txt:

PS C:\Users\Administrator>  Get-Content C:\scripts\DNSHostName.txt
ws2019.test.local
pld111.test.local

He read the list of computers from the file I downloaded from AD but there is a problem

Invoke-Command : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:1 char:30
+ ... ommand -ComputerName (Get-Content C:\scripts\DNSHostName.txt)  -Scrip ...
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand

How can you make "invoke-command" get the name of computers from a file?

Remote Desktop
Remote Desktop
A Microsoft app that connects remotely to computers and to virtual apps and desktops.
4,387 questions
0 comments No comments
{count} votes