Private/Invoke-FSMRemote.ps1
|
function Invoke-FSMRemote { <# .SYNOPSIS Runs a script block on a remote server over WinRM, with optional credentials. .DESCRIPTION Central wrapper around Invoke-Command so every public function gets the same remoting behaviour: consistent error action, optional -Credential support, and a single place to change remoting logic later. Analogy: every function in this module needs to "phone" a remote server. Rather than each one dialling separately, they all go through this switchboard. .PARAMETER ComputerName The remote server to run against. .PARAMETER ScriptBlock The code to execute remotely. .PARAMETER ArgumentList Arguments passed positionally into the script block's param() block. Wrap a single array argument with the comma operator, e.g. (,$myArray), so it arrives as one argument rather than being unrolled. .PARAMETER Credential Optional credentials to authenticate to the remote server. If omitted, the current session's identity is used. #> [CmdletBinding()] param( [Parameter(Mandatory)] [string]$ComputerName, [Parameter(Mandatory)] [scriptblock]$ScriptBlock, [object[]]$ArgumentList, [pscredential]$Credential ) $params = @{ ComputerName = $ComputerName ScriptBlock = $ScriptBlock ErrorAction = 'Stop' } if ($PSBoundParameters.ContainsKey('ArgumentList') -and $null -ne $ArgumentList) { $params.ArgumentList = $ArgumentList } if ($Credential) { $params.Credential = $Credential } Invoke-Command @params } |