Hi all
i have come through a confusion between following two commands
Command
$session = New-PSSession -ComputerName KASUNRAJAPAKSE,localhost
Get-PSSession
Id Name ComputerName State ConfigurationName Availability
2 Session2 localhost Opened Microsoft.PowerShell Available
1 Session1 KASUNRAJAPAKSE Opened Microsoft.PowerShell Available
Invoke-Command -Command { Get-WmiObject -Class win32_ComputerSystem } -Session ( Get-PSSession -ComputerName localhost )
when i run the above command it gives me the following error Invoke-Command : Cannot validate argument on parameter 'Session'. 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:80 + Invoke-Command -Command { Get-WmiObject -Class win32_ComputerSystem } -Session ( ... + ~ + CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
Command 2
Invoke-Command -Command { Get-WmiObject -Class win32_ComputerSystem } -Session $session[1]
this command works as i expected
can anyone explain why first one doesn’t work
thanks