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:
- Is there another solution?
- 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)?