Author Posts

December 24, 2016 at 7:12 pm

Hello and merry Christmas to you all.

I have two machines (MYCLIENT and MYSERVER). The server has a constrained WSMAN endpoint (SessionType RestrictedRemoteServer, LanguageMode NoLanguage, RunAsVirtualAccount, VisibleFunctions Func1 and Func2). It is registered as NameOfTheCustomEndPoint

In a script I try
$TestSession = New-PSSession -ComputerName MYSERVER -ConfigurationName NameOfTheCustomEndPoint
Invoke-Command -Session $TestSession -ScriptBlock {Func1 -Param1 "Value1" -Param2 "Value2"}
and this works OK

Invoke-Command -Session $TestSession -ScriptBlock {$Val1 = "Value1"; Func1 -Param1 $Val1 -Param2 "Value2"}
fails because of the NoLanguage option

So how do I pass a variable as a parameter value?

I found one workaround:
Import-PSSession -Session $TestSession
$Val1 = "Value1"
Func1 -Parm1 $Val1 -Param2 "Value2"

But I have two questions about this:
1. Is there another solution?
2. This allows me to execute script code AND use the exported functionality of the custom/constrained endpoint, do I risk someone abusing this (i.e. executing anything else than Func1 and Func2 on MYSERVER)?

December 24, 2016 at 7:56 pm

Ho ho ho ... 😉

Did you read the help for Invoke-Command including the examples? I think example number 9 could help you. And the explanation of -Argumentlist could help you as well.

Merry Christmas to you too and a generous Santa Claus 😀

December 26, 2016 at 11:30 am

Hello Olaf,

I just tested both the $Using syntax of example 9 and the -Argumentslist and they both work.

$MyVariable = "Value1"
Invoke-Command -Session $TestSession -Command {Func1 -Param1 $Args[0] -Param2 "Value2"} -ArgumentList @($MyVariable)
Invoke-Command -Session $TestSession -Command {Func1 -Param1 $Using:MyVariable -Param2 "Value2"}

(observation: the $Using method works for privileged accounts, if I connect with an account that has only execute permission on the endpoint then only the -Argumentlist method works)

Thanks,
Kris.

December 26, 2016 at 4:00 pm

Great ... glad that it was helpful.

BTW: Your name is not Kris Kringle, right? 😉 😀