References > Aliases > Remote Execution vs. Local Execution

Remote Execution vs. Local Execution

When you select remote execution, SAM creates a remote session via WinRM on the target server.  The script is then copied to the target server and run there. 

When you select local execution, a local version of the PowerShell console will open. If you need to run specific non-default cmdlets for the target server, you should have the needed cmdlets installed on the SAM machine.

The following script can be used inside of SAM (local/remote execution modes) and outside of SAM in the PowerShell console. The script returns 0 and the Hostname of the SAM machine (SAM local execution) or the Hostname of the target machine (SAM remote execution). In the Windows PowerShell console, the script returns the local machine Hostname. If for some reason the script cannot get the hostname, it returns 1 and a message of “Host not found.”

Script:

$stat = $env:computername;
if ($stat -ne $null)
  {
  Write-Host "Statistic: 0";
  Write-Host "Message: $stat";
  }
else
  {
  Write-Host "Statistic: 1";
  Write-Host "Message: Host not found";
  }

To save this script as a PowerShell (ps1) file:

In Notepad, save the script as Get-Date.ps1 (You can rename an existing file from *.txt to *.ps1.)

To open the PowerShell console:

For Windows x64:

  • For x64, navigate to Start > Accessories > Windows PowerShell > Windows PowerShell
  • For x86, navigate to: Start > Accessories > Windows PowerShell > Windows PowerShell (x86)


For Windows x86:

  • Navigate to Start > Accessories > Windows PowerShell > Windows PowerShell

To run this command via remote execution:

invoke-command –ComputerName SOME_PC -Credential SOME_PC\SOME_USER -ScriptBlock { Get-Date }

To run this command via local execution:

Name the file Get-Date.ps1 and run it by double-clicking it.