Invoke-Command is a very good option for running remote commands on a destination Windows host. It allows to run direct commands or execute a Powershell script ( on remote server). I also remember having to use Get-WmiObject as well, but Invoke-Command is definitely simpler.
It has the following prerequisites.
1. On the Powershell console of the Destination Windows host, configure winrm ( Windows Remote Management ).
2. Make your WFA server as a TrustedHost: winrm set winrm/config/client @{TrustedHosts="wfahost_name_or_IP"}
3. This is enough to get the command execution working. But there are other winrm config option you can set as per your needs. Read more here :http://pubs.vmware.com/orchestrator-plugins/index.jsp?topic=%2Fcom.vmware.using.powershell.plugin.doc_10%2FGUID-D4ACA4EF-D018-448A-866A-DECDDA5CC3C1.h...
Attaching the command which can be imported in a WFA2.1 or above. I must say,it was little more difficult than I initially thought. WFA doesn't support [scriptblock] as an input parameter type. So the command in [string] entered needs to be created as a [ScriptBlock] type in the code.
Command code:
===
param (
[parameter(Mandatory=$false, HelpMessage="Command to execute")]
[string]$CmdBlock,
[parameter(Mandatory=$true, HelpMessage="Windows Host Name")]
[string]$WinHost,
[parameter(Mandatory=$false, HelpMessage="Posh script path")]
[string]$PoshScript
)
$creds = Get-WfaCredentials -Host $WinHost
# Convernt string command block to Script Block
$ScriptBlock = [Scriptblock]::Create($CmdBlock)
if ($CmdBlock) {
$returnData= Invoke-Command -ComputerName $WinHost -Credential $creds -ScriptBlock $ScriptBlock
Get-WFALogger -Info -Message $returnData
}
if ($PoshScript) {
# Posh Script should be present on the WFA server.
Invoke-Command -ComputerName $WinHost -Credential $creds -FilePath $PoshScript
}
=====
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.