I'm running into an issue running Invoke-Command, I get the error below. I have successfully created a PSSession and ensured CredSSP is working properly (for both Server and Client roles). The command works fine if I don't use -Authentication, but then my credentials aren't passed.
PS C:\Users\saleemiw.da> $psession
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Session1 COMPUTER1 Opened Microsoft.PowerShell Available
PS C:\Users\saleemiw.da> $cred
UserName
Password
--------
--------
COCOLYNN\saleemiw.da System.Security.SecureString
PS C:\Users\saleemiw.da> Invoke-Command -Session $psession -ScriptBlock {Get-SPFarm} -Authentication CredSSP -Credential $cred
Invoke-Command : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:15
+ Invoke-Command <<<< -Session $psession -ScriptBlock {Get-SPFarm} -Authentication CredSSP -Credential $cred
+ CategoryInfo : InvalidArgument: (:) [Invoke-Command], Parameter
BindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand
I ran this from a remote server as well as the local server itself, same result.
This does work:
Invoke-Command -cn localhost -ScriptBlock {Add-PSSnapin -Name Microsoft.SharePoint.PowerShell;Get-SPFarm} -Authentication CredSSP -Credential $cred
However, if I have a series of commands, that means I need to load the SharePoint Snapin each time. Are there any workarounds to this?