Share via


Common PS Remoting + GameDev Use Cases guidance


Use cases
Securely connecting to a remote device
Run arbitrary commands remotely
Install components remotely

Pre-requisite and assumptions

The examples in the following sections assume you have successfully completed the setup for the Xbox Device Manager Module (XDM) and the Remote Iterating tooling on both the local device and the remote device.

Instructions on how to set up the XDM and the remote iteration tools can be found in this quick start guide


Use cases examples


Securely connecting to a remote device

Option 1. Interactive session:

Create an interactive session providing the username to be used on the target device and hostname or address of the target device

Connect-XdmTargetDevice -HostName <username>@<hostName|address> -Interactive 

Option 2. Create a remote session variable:

Create a session variable providing the username to be used on the target device and hostname or address of the target device

$session = (Connect-XdmTargetDevice –HostName <username>@<hostName|address>).session 

Creating the remote session variable will allow you run commands on demand without the need for an interactive session


Run arbitrary commands remotely

Use the session variable created when setting up the connection

Invoke-Command -Session $session {Command and parameters to run remotely go here} 

Example:

Invoke-Command -Session $session {Get-Process} 

Install components remotely

From Winget

Invoke-Command -Session $session {winget install --id Valid Winget package ID goes here --accept-source-agreements --accept-package-agreements} 

From other package managers

Invoke-Command -Session $session {choco install Valid chocolatey package ID goes here -y} 

Installing a MSI package

Invoke-Command -Session $session {Start-Process msiexec.exe -ArgumentList '/i C:\Installers\example.msi /quiet /norestart' -Wait} 

Installing from a network share

Invoke-Command -Session $session {Start-Process "\\fileserver\share\installer.exe" -ArgumentList "/S" -Wait} 

Note

Not all .exe installers support /S. Some may use /silent, /quiet, or other flags. Always check the vendor’s documentation or run installer.exe /? to see supported options.


Copy and share files between devices

Using scp to copy files from remote device

scp <username>@<hostName>:<remote_path> <local_path> 

Using scp to copy files to remote device

scp <local_path> <username>@<remote_host>:<remote_path> 

Note

Note: Use scp –r to copy entire folders


Create a shared folder

Invoke-Command -Session $session { $folderPath = "C:\Shared\Logs"     

New-Item -Path $folderPath -ItemType Directory -Force   

New-SmbShare -Name "LogsShare" -Path $folderPath -FullAccess "Administrators"} 

Copy files differentially

Invoke-Command -Session $session {robocopy "\\yourhost\source" "C:\TargetFolder" /MIR /Z /FFT /R:2 /W:5} 

Robocopy flags:

/MIR – Mirror source to destination (adds new, removes deleted).

/Z – Enables restartable mode (good for network resilience).

/FFT – Assumes FAT file times (2-second granularity, useful for cross-platform).

/R:2 – Retry 2 times on failure.

/W:5 – Wait 5 seconds between retries.

Other examples

PowerShell remoting is a powerful tool and offers a myriad of options. Unless a task is completely domain bound and very specific, there is probably a way to do it through PowerShell Remoting. If there is something you want to achieve, but you are unsure about how to go about it using PowerShell, ask Copilot! It is fairly competent at PowerShell.

Here are some miscellaneous examples provided by Copilot of other things you can do:

Cleanup / Rollback remote device

Remove temporary files and logs:

Invoke-Command -Session $session { 

    Remove-Item -Path "C:\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue 

    Remove-Item -Path "C:\Logs\*" -Recurse -Force -ErrorAction SilentlyContinue} 

Uninstall components:

Invoke-Command -Session $session {Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "*YourAppName*" } | ForEach-Object { $_.Uninstall() }} 

Manage Windows user accounts

Get remote local users

Invoke-Command -Session $session {Get-LocalUser} 

Get Users group members

Invoke-Command -Session $session {Get-LocalGroupMember -Group "Administrators"} 

Create new user

Invoke-Command -Session $session {
$password = ConvertTo-SecureString "P@ssw0rd123" -AsPlainText -Force 
New-LocalUser -Name "devuser" -Password $password -FullName "Developer User" -Description "Temporary dev account"} 

Add user to a group

Invoke-Command -Session $session {Add-LocalGroupMember -Group "Administrators" -Member "devuser"} 

Manage Network settings and firewall

Get network adapter info*

Invoke-Command -Session $session {Get-NetIPAddress}

Set static IP address

Invoke-Command -Session $session {New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress "192.168.1.50" -PrefixLength 24 -DefaultGateway "192.168.1.1"} 

Allow inbound port

Invoke-Command -Session $session {New-NetFirewallRule -DisplayName "Allow TCP 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow} 

Manage Windows configuration settings

Apply power settings

Invoke-Command -Session $session {powercfg -setactive SCHEME_MIN} 

References

PowerShell remoting

PowerShell Remoting FAQ