This code allow you execute remotely PowerShell commands that have parameter "-cimSession" as option to connect remotely (i.e. Get-ScheduledTask)
If a command provide this parameter, use CimSession over PSSession because the former is newer and more versatil on execution
Copy text below into a power shell session and execute to see the code in action.
# Scripting - Remote PowerShell Execution with CimSession - returning remote information # Core Snippet & Sample # www.PowerShellExamples.com # Commands to run in a remote computer using CimSession $cimSession = New-CimSession -ComputerName "ComputerNameXXX" get-ScheduledTask ("Scheduled*") -CimSession $cimSession $cimSession | Remove-CimSession
PS C:\> TaskPath TaskName State PSComputerName -------- -------- ----- -------------- \Microsoft\Windows\Defrag\ ScheduledDefrag Ready xxxxxxxxxxxx \Microsoft\Windows\Diagnosis\ Scheduled Ready xxxxxxxxxxxx \Microsoft\Windows\WindowsUpdate\ Scheduled Start Ready xxxxxxxxxxxx