start-job

Invoke a second script with arguments from a script

浪尽此生 提交于 2019-11-29 20:24:00
I have a script that reads a configuration file that results in a set of name value pairs that I would like to pass as arguments to a function in a second PowerShell script. I do not know what parameters will be placed in this configuration file at design time, so right at the point where I need to invoke this second PowerShell script, I basically just have one variable that has the path to this second script, and a second variable that is an array of arguments to pass to the script identified in the path variable. So the variable containing the path to the second script ($scriptPath), might

Powershell pass variable to start-job

核能气质少年 提交于 2019-11-27 04:49:18
within powershell I'd like to learn the best way to call a variable to a start job so I don't have to edit the script for each server as it will be specific based on the client I've placed my script on. $Servername = 'Server1' $pingblock = { pathping $servername | Out-File C:\client\PS\ServerPing.TXT } start-job $pingblock when I run my code above I just get a file with the help as if I forgot the specify the $servername. Use the -ArgumentList parameter on Start-Job e.g.: Start-Job -Scriptblock {param($p) "`$p is $p"} -Arg 'Server1' In your case: $pingblock = {param($servername) pathping

Powershell: Run multiple jobs in parralel and view streaming results from background jobs

强颜欢笑 提交于 2019-11-27 03:14:54
问题 Overview Looking to call a Powershell script that takes in an argument, runs each job in the background, and shows me the verbose output. Problem I am running into The script appears to run, but I want to verify this for sure by streaming the results of the background jobs as they are running. Code ###StartServerUpdates.ps1 Script### #get list of servers to update from text file and store in array $servers=get-content c:\serverstoupdate.txt #run all jobs, using multi-threading, in background

Powershell pass variable to start-job

南楼画角 提交于 2019-11-26 09:11:36
问题 within powershell I\'d like to learn the best way to call a variable to a start job so I don\'t have to edit the script for each server as it will be specific based on the client I\'ve placed my script on. $Servername = \'Server1\' $pingblock = { pathping $servername | Out-File C:\\client\\PS\\ServerPing.TXT } start-job $pingblock when I run my code above I just get a file with the help as if I forgot the specify the $servername. 回答1: Use the -ArgumentList parameter on Start-Job e.g.: Start