scripting - Invoking two commands at the same time powershell -
scripting - Invoking two commands at the same time powershell -
i invoke 2 commands @ same time when entering parameters illustration if execute code put:
abcdef folder1 folder2
and create 2 folders on desktop.
the code below illustration want know right syntax doing it.
function abcdef { param($folder1, $folder2) $s = $executioncontext.invokecommand.newscriptblock("mkdir c:\'documents , settings'\x\desktop\$folder1") $s1 = $executioncontext.invokecommand.newscriptblock("mkdir c:\'documents , settings'\x\desktop\$folder2") invoke-command -computername $computerremote -scriptblock $s,$s1 -credential $cred }
function abcdef { param( [parameter(mandatory=$true,position=0,valuefrompipeline=$true)] [validatenotnullorempty] [string[]] $computername, [parameter(mandatory=$true,position=1)] [validatenotnullorempty()] [string[]] $folders, [parameter(mandatory=$true,position=2)] [validatenotnullorempty()] [pscredential] $cred ) foreach($computer in $computername){ foreach($folder in $folders{ $s = { new-item "c:\documents , settings\x\desktop\$folder" -type directory } invoke-command -computername $computer -scriptblock $s -credential $cred } } }
you can phone call function this:
abcdef $computernames $folders $credentials
or can pipe computernames action on computers previous command returns (in illustration advertisement computers):
get-adcomputer -filter * | abcdef $folders $credentials
also notice dont utilize mkdir
, should allways utilize cmdlets if 1 available action trying execute
powershell scripting
Comments
Post a Comment