<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Isaac&#039;s Blog &#187; get-job | stop-job</title>
	<atom:link href="http://blog.isaacblum.com/tag/get-job-stop-job/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.isaacblum.com</link>
	<description>So Many Rambles So Little Time....</description>
	<lastBuildDate>Wed, 28 Dec 2011 21:10:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PowerShell Multithreading &#8211; OMG!!</title>
		<link>http://blog.isaacblum.com/2010/01/22/powershell-multithreading-omg/</link>
		<comments>http://blog.isaacblum.com/2010/01/22/powershell-multithreading-omg/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 18:43:23 +0000</pubDate>
		<dc:creator>IsaacBlum</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[For The Greater Good]]></category>
		<category><![CDATA[Free Help]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[get-job]]></category>
		<category><![CDATA[get-job | stop-job]]></category>
		<category><![CDATA[get-job | wait-job]]></category>
		<category><![CDATA[Multithreading]]></category>
		<category><![CDATA[OMG]]></category>
		<category><![CDATA[start-job]]></category>
		<category><![CDATA[start-job -filepath]]></category>
		<category><![CDATA[stop-job]]></category>
		<category><![CDATA[threading]]></category>
		<category><![CDATA[wait-job]]></category>

		<guid isPermaLink="false">http://blog.isaacblum.com/?p=268</guid>
		<description><![CDATA[This is an example of a very simple multi thread script. All it does is output 2 user names per function. But you can only imagine the power. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [...]]]></description>
			<content:encoded><![CDATA[<p>This is an example of a very simple multi thread script. All it does is output 2 user names per function.<br />
But you can only imagine the power.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#Create a function, or in this example create/split up a large job into multiple functions.</span>
&nbsp;
<span style="color: #008000;">#Step 1 : Create threading.ps1</span>
<span style="color: #008000;">#Step 2 : Create function and add it to threading.ps1</span>
&nbsp;
<span style="color: #008000;">#(Sample Function)</span>
&nbsp;
<span style="color: #0000FF;">function</span> one<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$users1</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;CORP1Bollasr1&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;CORP2aardeje1&quot;</span>
		<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$u</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$users1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">&quot;$u&quot;</span>
		<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
one <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> C:lnloneresults.txt
&nbsp;
&nbsp;
<span style="color: #008000;">#Step 3 : Wrap the function inside a function with (Write-Output ' ')  around each line. </span>
<span style="color: #008000;">#(Sample Wrapped Function)</span>
&nbsp;
<span style="color: #0000FF;">function</span> createone<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function one{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users1 = &quot;CORP1Bollasr1&quot;, &quot;CORP2aardeje1&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users1){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'one | out-File C:lnloneresults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #008000;">#Now I will show an example of 5 threads. This file is called threading.ps1</span>
&nbsp;
<span style="color: #008000;">##Create Multi Thread Script</span>
<span style="color: #0000FF;">function</span> createone<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function one{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users1 = &quot;CORP1Bollasr1&quot;, &quot;CORP2aardeje1&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users1){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'one | out-File C:lnloneresults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">function</span> createtwo<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function two{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users2 = &quot;CORP1dudlesu1&quot;, &quot;CORP2duerrma1&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users2){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'two | out-File C:lnltworesults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">function</span> createthree<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function three{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users3 = &quot;CORP1khattpa2&quot;, &quot;CORP1khattsa1&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users3){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'three | out-File C:lnlthreeresults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">function</span> createfour<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function four{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users4 = &quot;CORP1pellath1&quot;, &quot;CORP2pellian5&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users4){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'four | out-File C:lnlfourresults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">function</span> createfive<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function five{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users5 = &quot;CORP1trancu1&quot;, &quot;CORP2tranth8&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users5){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'five | out-File C:lnlfiveresults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #008000;">#Step 4 : Create .ps1 scripts out of the functions.</span>
<span style="color: #008000;">#Take note that .... alows for a releative path.</span>
&nbsp;
createone <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> ....Threadone.ps1
createtwo <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> ....Threadtwo.ps1
createthree <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> ....Threadthree.ps1
createfour <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> ....Threadfour.ps1
createfive <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> ....Threadfive.ps1
&nbsp;
&nbsp;
<span style="color: #008000;">#Step 5 : Launch threading script.</span>
&nbsp;
start<span style="color: pink;">-</span>job <span style="color: #008080; font-style: italic;">-filepath</span> ....Threadone.ps1
start<span style="color: pink;">-</span>job <span style="color: #008080; font-style: italic;">-filepath</span> ....Threadtwo.ps1
start<span style="color: pink;">-</span>job <span style="color: #008080; font-style: italic;">-filepath</span> ....Threadthree.ps1
start<span style="color: pink;">-</span>job <span style="color: #008080; font-style: italic;">-filepath</span> ....Threadfour.ps1
start<span style="color: pink;">-</span>job <span style="color: #008080; font-style: italic;">-filepath</span> ....Threadfive.ps1
&nbsp;
<span style="color: #008000;">#Step 6 : Check Status of Jobs</span>
<span style="color: #008000;">#The Wait-Job cmdlet waits for Windows PowerShell background jobs to complete before it displays the command prompt.</span>
&nbsp;
get<span style="color: pink;">-</span>job <span style="color: pink;">|</span> wait<span style="color: pink;">-</span>job
&nbsp;
<span style="color: #008000;">#Step 7 : Stop any Job that may be hung.</span>
<span style="color: #008000;">#The Stop-Job cmdlet stops Windows PowerShell background jobs that are in progress.</span>
&nbsp;
get<span style="color: pink;">-</span>job <span style="color: pink;">|</span> stop<span style="color: pink;">-</span>job
&nbsp;
<span style="color: #008000;">#full Script called threading.ps1</span>
<span style="color: #008000;">##Create Multi Thread Script</span>
&nbsp;
<span style="color: #0000FF;">function</span> createone<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function one{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users1 = &quot;CORP1Bollasr1&quot;, &quot;CORP2aardeje1&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users1){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'one | out-File C:lnloneresults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">function</span> createtwo<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function two{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users2 = &quot;CORP1dudlesu1&quot;, &quot;CORP2duerrma1&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users2){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'two | out-File C:lnltworesults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">function</span> createthree<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function three{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users3 = &quot;CORP1khattpa2&quot;, &quot;CORP1khattsa1&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users3){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'three | out-File C:lnlthreeresults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">function</span> createfour<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function four{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users4 = &quot;CORP1pellath1&quot;, &quot;CORP2pellian5&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users4){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'four | out-File C:lnlfourresults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">function</span> createfive<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'function five{'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'	$users5 = &quot;CORP1trancu1&quot;, &quot;CORP2tranth8&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		foreach ($u in $users5){'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'			Write-Output &quot;$u&quot;'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'		}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'}'</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">'five | out-File C:lnlfiveresults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
createone <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> ....Threadone.ps1
createtwo <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> ....Threadtwo.ps1
createthree <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> ....Threadthree.ps1
createfour <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> ....Threadfour.ps1
createfive <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out<span style="color: #FF0000;">-File</span></span> ....Threadfive.ps1
&nbsp;
start<span style="color: pink;">-</span>job <span style="color: #008080; font-style: italic;">-filepath</span> ....Threadone.ps1
start<span style="color: pink;">-</span>job <span style="color: #008080; font-style: italic;">-filepath</span> ....Threadtwo.ps1
start<span style="color: pink;">-</span>job <span style="color: #008080; font-style: italic;">-filepath</span> ....Threadthree.ps1
start<span style="color: pink;">-</span>job <span style="color: #008080; font-style: italic;">-filepath</span> ....Threadfour.ps1
start<span style="color: pink;">-</span>job <span style="color: #008080; font-style: italic;">-filepath</span> ....Threadfive.ps1
&nbsp;
get<span style="color: pink;">-</span>job <span style="color: pink;">|</span> wait<span style="color: pink;">-</span>job
&nbsp;
get<span style="color: pink;">-</span>job <span style="color: pink;">|</span> stop<span style="color: pink;">-</span>job</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.isaacblum.com/2010/01/22/powershell-multithreading-omg/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

