I'm having trouble passing variables from a PowerShell script into a SPE Script. I'm attempting to call the SPE script from a PowerShell file on the file system. I'm trying to pass in variables that can be used by the script, but they appear to always be empty from the viewpoint of the script. When I try to call the script directly from within ISE in Sitecore, the values are accessible.
Here's what I'm trying:
The PowerShell Script:
I'm referencing a script via GUID and passing in a varaible named "name."
$scriptArguments = @{
"name" = "CRAAIG"
}
Write-Host "scriptArguments: $($scriptArguments.name)"
$session = New-ScriptSession -Username admin -Password b -ConnectionUri http://sc920.local
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock { Get-Item -Path "master:" -ID "{790F6017-B495-4C8C-B9CF-6119669E1688}" | Invoke-Script -ArgumentList $scriptArguments } -AsJob
Wait-RemoteScriptSession -Session $session -Id $jobId -Delay 5 -Verbose
Stop-ScriptSession -Session $session
The SPE Script
I've obviously boiled it down here, but all I'd like to do is access the variables passed in. I'm attempting to writing the values to the SPE log.
param($params)
Write-Log "params: $($params)"
Write-Log "params.name: $($params.name)"
Write-Log "args: $($args)"
Write-Log "args.name $($args.name)"
The Results in the Log File
All of these values end up null.
ManagedPoolThread #15 09:46:04 INFO params:
ManagedPoolThread #15 09:46:04 INFO params.name:
ManagedPoolThread #15 09:46:04 INFO args:
ManagedPoolThread #15 09:46:04 INFO args.name
As mentioned, I have attempted to call the script itself from within ISE and when take Invoke-RemoteScript
out of it and call:
$scriptArguments = @{
"name" = "CRAAIG"
}
Get-Item -Path "master:" -ID "{790F6017-B495-4C8C-B9CF-6119669E1688}" | Invoke-Script -ArgumentList $scriptArguments
The variables can be received in the $args
variable as a hashtable in this manner.
This appears to be following what Michael and Ben have said in a couple of places (How to pass arguments to SPE's Invoke-RemoteScript and Sitecore PowerShell Extensions Remoting variables not working in Octopus Deploy), but I can't make it work.
PS - Last thought that just occurred to me: Does HTTPS have anything to do with it? I'm just using HTTP locally and thought that the config supported this. Relevant section from showconfig:
<remoting requireSecureConnection="false" enabled="true">
<authorization>
<add Permission="Allow" IdentityType="User" Identity="sitecore\admin" patch:source="Cognifide.PowerShell.Patch.config"/>
</authorization>
</remoting>
Am I missing something fundamental here?
Thanks!