On a CredSSP enabled server is a .psm1 script file that gets executed remotely from a client technology. The client passes in a couple execution parameters and the server script returns an object back to the client. This works great but the pattern I've implemented feels clunky. Is there room for improvement?
Client code calling remote server script:
$firstStanza=@{
a = "Mary had"
b = "a little"
c = "lamb"
}
$secondStanza=@{
d = "its fleece"
e = "was white"
f = "as snow"
}
$scriptBlock = {
Param([Parameter(Mandatory=$true)]$param1,[Parameter(Mandatory=$true)]$param2)
Import-Module C:\CreateNewObject.psm1
CombineBothStanzas -firstStanza $param1 -secondStanza $param2
}
$bothStanzasCombined = Invoke-Command -ComputerName serverName.internalDomain.com -ScriptBlock $scriptBlock -ArgumentList $firstStanza,$secondStanza
Write-Output $bothStanzasCombined
Contents of remote script on server c:\CreateNewObject.psm1:
function CombineBothStanzas {
Param([Parameter(Mandatory=$true)]$firstStanza,[Parameter(Mandatory=$true)]$secondStanza)
return ($firstStanza + $secondStanza).GetEnumerator() | sort -Property name
}
Remote server script operation returns this object to the client:
Name Value
---- -----
a Mary had
b a little
c lamb
d its fleece
e was white
f as snow