Calling function in a Parallel foreach loop
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Calling function in a Parallel foreach loop
I know start-sleep. I mean how would I use that in the in the parallel code?
Re: Calling function in a Parallel foreach loop
Ok thanks. Last question If I run in parallel a trigger to run a schedule task on a remote computer that calls a MSI to install will this have the same issue of dying before completed?
Workflow version
Workflow version
- workflow Invoke-Installer
- {
- param (
- [string[]]$servers
- )
- foreach -parallel ($server in $servers)
- {
- InlineScript
- {
- $install = {
- Start-ScheduledTask -TaskName "MSI_INSTALLER"
- }
- Invoke-Command -Scriptblock $install -Computer $using:server
- }
- }
- }
- | ForEach-Object -Parallel {
- Invoke-Command -ComputerName $_ -ScriptBlock {
- Start-ScheduledTask -TaskName "MSI_INSTALLER"
- }
- }
-
- Posts: 14672
- Joined: Tue May 22, 2007 9:57 am
- Has voted: 1 time
- Been upvoted: 5 times
- Contact:
Re: Calling function in a Parallel foreach loop
Yes. The installer woks that way. Without waiting the session will terminate on most MSI installs before the install is complete. You must wait in the session until the install is complete.
You can use ConfigMgr from DSC to ask the remote OS to fully manage and maintain the install.
You can use ConfigMgr from DSC to ask the remote OS to fully manage and maintain the install.