0

PowerShell 5.1

How does computer name array for invoke-comman and gwmi work? Do I need to omit one of them? or include both of them? What is going to be the behavior?

function fx1(){
    Invoke-Command -ComputerName Computer1, Computer2, doesNotexist -ScriptBlock {        
        gwmi win32_service -computer [computername] -filter "name='whatever'"
    } -ErrorAction SilentlyContinue -ErrorVariable errors
}
Rod
  • 14,529
  • 31
  • 118
  • 230
  • 2
    if you're looking to invoke `gwmi` in those servers then it shouldnt have `-computer` since the command is executing remotely already – Santiago Squarzon Feb 27 '23 at 21:27
  • 1
    Does this answer your question? [How do I pass variables with the Invoke-Command cmdlet?](https://stackoverflow.com/questions/36328690/how-do-i-pass-variables-with-the-invoke-command-cmdlet) – JosefZ Feb 27 '23 at 21:39
  • Best I found is following : https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?source=recommendations&view=powershell-7.3#notes – jdweng Feb 28 '23 at 07:28

0 Answers0