Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to propagate CmdletBinding parameters through Invoke-Command?

$
0
0

I have a set of scripts with the CmdletBinding attribute applied that run scripts on other servers.

For example, I have a Stop-MyServices that stops my services on all my servers:

function Stop-MyServices {
  [CmdletBinding(SupportsShouldProcess = $true)]
  param (
    [switch]$Force = $true
  )

  Invoke-Command -ComputerName $MyComputers `
    -ArgumentList $Force `
    -ScriptBlock {
      param ($Force)
	  
      & C:\Scripts\Stop-MyServices.ps1 -Force:$force
  }
}

What I would like to happen is that, when issue this command:

Stop-MyServices -WhatIf

the WhatIf switch propagates into the C:\Scripts\Stop-MyServices.ps1 script on each machine.

How can I do it?


Paulo Morgado



Viewing all articles
Browse latest Browse all 21975

Trending Articles