<<< Back to Search

Scripting ::: Remote PowerShell Execution with CimSession - returning remote information

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

Core Snippet & Sample

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 &amp; 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






Result

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