<?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; PowerShell</title>
	<atom:link href="http://blog.isaacblum.com/category/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.isaacblum.com</link>
	<description>So Many Rambles So Little Time....</description>
	<lastBuildDate>Fri, 14 May 2010 20:26:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>To get and store the credential for the current user</title>
		<link>http://blog.isaacblum.com/2010/02/18/to-get-and-store-the-credential-for-the-current-user/</link>
		<comments>http://blog.isaacblum.com/2010/02/18/to-get-and-store-the-credential-for-the-current-user/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 19:11:09 +0000</pubDate>
		<dc:creator>Isaac Blum</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[-AsSecureString]]></category>
		<category><![CDATA[ConvertTo-SecureString]]></category>
		<category><![CDATA[get-content]]></category>
		<category><![CDATA[new-object]]></category>

		<guid isPermaLink="false">http://blog.isaacblum.com/?p=300</guid>
		<description><![CDATA[Thank sean. 1 2 $notespw = Read-Host &#34;Enter the password for the Notes ID file&#34; -AsSecureString $notespw &#124; ConvertFrom-SecureString &#124; Set-Content $pwfile -force To retrieve the password and create the PSCredential object: 1 2 $notespw = get-content $pwfile &#124; ConvertTo-SecureString $notesid = new-object -typename system.management.automation.pscredential -argumentlist &#34;-default-&#34;,$notespw Example of use: 1 Get-DominoMailbox mary@contoso.com -SourceCredential $notesid]]></description>
			<content:encoded><![CDATA[<p><a href="http://diginomicon.net/">Thank sean.</a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$notespw</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;Enter the password for the Notes ID file&quot;</span> <span style="color: #008080; font-style: italic;">-AsSecureString</span>
<span style="color: #800080;">$notespw</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ConvertFrom-SecureString</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Set-Content</span> <span style="color: #800080;">$pwfile</span> <span style="color: #008080; font-style: italic;">-force</span></pre></td></tr></table></div>

<p>To retrieve the password and create the PSCredential object:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$notespw</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">get-content</span> <span style="color: #800080;">$pwfile</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ConvertTo-SecureString</span>
<span style="color: #800080;">$notesid</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> <span style="color: #008080; font-style: italic;">-typename</span> system.management.automation.pscredential <span style="color: #008080; font-style: italic;">-argumentlist</span> <span style="color: #800000;">&quot;-default-&quot;</span><span style="color: pink;">,</span>$notespw</pre></td></tr></table></div>

<p>Example of use:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>DominoMailbox mary<span style="color: pink;">@</span>contoso.com <span style="color: pink;">-</span>SourceCredential $notesid</pre></td></tr></table></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.isaacblum.com%2F2010%2F02%2F18%2Fto-get-and-store-the-credential-for-the-current-user%2F&amp;linkname=To%20get%20and%20store%20the%20credential%20for%20the%20current%20user"><img src="http://blog.isaacblum.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.isaacblum.com/2010/02/18/to-get-and-store-the-credential-for-the-current-user/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Powershell Version of CMD SET</title>
		<link>http://blog.isaacblum.com/2010/02/18/powershell-version-of-cmd-set/</link>
		<comments>http://blog.isaacblum.com/2010/02/18/powershell-version-of-cmd-set/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 18:58:14 +0000</pubDate>
		<dc:creator>Isaac Blum</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[For The Greater Good]]></category>
		<category><![CDATA[Free Help]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://blog.isaacblum.com/?p=291</guid>
		<description><![CDATA[Thank you wes If you are like me and are just so used to typing set to list and set environment variables then you might find this script useful. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 if &#40;test-path alias:set&#41; &#123; remove-item alias:set [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://weblogs.asp.net/whaggard/archive/2007/02/08/powershell-version-of-cmd-set.aspx"> Thank you wes </a></p>
<p>If you are like me and are just so used to typing set to list and set environment variables then you might find this script useful.</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
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">test-path</span> alias:<span style="color: #008080; font-weight: bold;">set</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-weight: bold;">remove-item</span> alias:<span style="color: #008080; font-weight: bold;">set</span> <span style="color: pink;">&gt;</span> <span style="color: #800080;">$null</span> <span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">function</span> <span style="color: #008080; font-weight: bold;">set</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$var</span> <span style="color: pink;">=</span> <span style="color: #000080;">$args</span>
	<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$var</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-weight: bold;">get-childitem</span> env: <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">sort-object</span> name
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">else</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$var</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;^(\S*?)\s*=\s*(.*)$&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-weight: bold;">set-item</span> <span style="color: #008080; font-style: italic;">-force</span> <span style="color: #008080; font-style: italic;">-path</span> <span style="color: #800000;">&quot;env:$($matches[1])&quot;</span> <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$matches</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">2</span><span style="color: #000000;">&#93;</span>;		
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0000FF;">else</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-weight: bold;">write-error</span> <span style="color: #800000;">&quot;ERROR Usage: VAR=VALUE&quot;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>	
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.isaacblum.com%2F2010%2F02%2F18%2Fpowershell-version-of-cmd-set%2F&amp;linkname=Powershell%20Version%20of%20CMD%20SET"><img src="http://blog.isaacblum.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.isaacblum.com/2010/02/18/powershell-version-of-cmd-set/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Isaac Blum</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;CORP1\Bollasr1&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;CORP2\aardeje1&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-File</span> C:\lnl\oneresults.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;CORP1\Bollasr1&quot;, &quot;CORP2\aardeje1&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:\lnl\oneresults.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;CORP1\Bollasr1&quot;, &quot;CORP2\aardeje1&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:\lnl\oneresults.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;CORP1\dudlesu1&quot;, &quot;CORP2\duerrma1&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:\lnl\tworesults.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;CORP1\khattpa2&quot;, &quot;CORP1\khattsa1&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:\lnl\threeresults.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;CORP1\pellath1&quot;, &quot;CORP2\pellian5&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:\lnl\fourresults.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;CORP1\trancu1&quot;, &quot;CORP2\tranth8&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:\lnl\fiveresults.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-File</span> ..\..\Threadone.ps1
createtwo <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-File</span> ..\..\Threadtwo.ps1
createthree <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-File</span> ..\..\Threadthree.ps1
createfour <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-File</span> ..\..\Threadfour.ps1
createfive <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-File</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;CORP1\Bollasr1&quot;, &quot;CORP2\aardeje1&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:\lnl\oneresults.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;CORP1\dudlesu1&quot;, &quot;CORP2\duerrma1&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:\lnl\tworesults.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;CORP1\khattpa2&quot;, &quot;CORP1\khattsa1&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:\lnl\threeresults.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;CORP1\pellath1&quot;, &quot;CORP2\pellian5&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:\lnl\fourresults.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;CORP1\trancu1&quot;, &quot;CORP2\tranth8&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:\lnl\fiveresults.txt'</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
createone <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-File</span> ..\..\Threadone.ps1
createtwo <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-File</span> ..\..\Threadtwo.ps1
createthree <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-File</span> ..\..\Threadthree.ps1
createfour <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-File</span> ..\..\Threadfour.ps1
createfive <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-File</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>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.isaacblum.com%2F2010%2F01%2F22%2Fpowershell-multithreading-omg%2F&amp;linkname=PowerShell%20Multithreading%20%26%238211%3B%20OMG%21%21"><img src="http://blog.isaacblum.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.isaacblum.com/2010/01/22/powershell-multithreading-omg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell &#8211; Bulk Update MOSS Profile</title>
		<link>http://blog.isaacblum.com/2010/01/21/powershell-bulk-update-moss-profile/</link>
		<comments>http://blog.isaacblum.com/2010/01/21/powershell-bulk-update-moss-profile/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 15:33:47 +0000</pubDate>
		<dc:creator>Isaac Blum</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[For The Greater Good]]></category>
		<category><![CDATA[Free Help]]></category>
		<category><![CDATA[MOSS 2007]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Bulk]]></category>
		<category><![CDATA[MOSS]]></category>
		<category><![CDATA[Profile]]></category>
		<category><![CDATA[SSP]]></category>
		<category><![CDATA[Update]]></category>

		<guid isPermaLink="false">http://blog.isaacblum.com/?p=257</guid>
		<description><![CDATA[The below links were used to create this script. Thanks http://blogs.msdn.com/powershell/archive/2009/01/10/capture-console-screen.aspx http://www.sharepointdevwiki.com/display/public/Updating+User+Profiles+in+SharePoint+SSP+using+PowerShell http://blogs.flexnetconsult.co.uk/colinbyrne/PermaLink,guid,a332015d-c5dc-4433-a0f3-247fd37b0b04.aspx Download the file here 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 [...]]]></description>
			<content:encoded><![CDATA[<p>The below links were used to create this script. Thanks</p>
<p>http://blogs.msdn.com/powershell/archive/2009/01/10/capture-console-screen.aspx</p>
<p>http://www.sharepointdevwiki.com/display/public/Updating+User+Profiles+in+SharePoint+SSP+using+PowerShell</p>
<p>http://blogs.flexnetconsult.co.uk/colinbyrne/PermaLink,guid,a332015d-c5dc-4433-a0f3-247fd37b0b04.aspx</p>
<p>Download the file <a href="http://isaacblum.com/wp-content/uploads/2010/01/Bulk-Update-MOSS-profiles.ps1">here</a></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
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>void<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>reflection.assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">Load</span>withpartialname<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.SharePoint&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-null</span>
<span style="color: #000000;">&#91;</span>void<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>reflection.assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">Load</span>withpartialname<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.Office.Server.Search&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-null</span>
<span style="color: #000000;">&#91;</span>void<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>reflection.assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">Load</span>withpartialname<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.Office.Server&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-null</span>
&nbsp;
<span style="color: #008000;">#################################################################################################################</span>
<span style="color: #008000;"># Get-ConsoleAsText.ps1</span>
<span style="color: #008000;"># Thanks to http://blogs.msdn.com/powershell/archive/2009/01/10/capture-console-screen.aspx for Get-ConsoleAsText.ps1</span>
<span style="color: #008000;"># The script captures console screen buffer up to the current cursor position and returns it in plain text format.</span>
<span style="color: #008000;">#</span>
<span style="color: #008000;"># Returns: ASCII-encoded string.</span>
<span style="color: #008000;">#</span>
<span style="color: #008000;"># Example:</span>
<span style="color: #008000;">#</span>
<span style="color: #008000;"># $textFileName = &quot;$env:temp\ConsoleBuffer.txt&quot;</span>
<span style="color: #008000;"># .\Get-ConsoleAsText | out-file $textFileName -encoding ascii</span>
<span style="color: #008000;"># $null = [System.Diagnostics.Process]::Start(&quot;$textFileName&quot;)</span>
<span style="color: #008000;">#################################################################################################################</span>
<span style="color: #0000FF;">function</span> Get<span style="color: pink;">-</span>ConsoleAsText<span style="color: #000000;">&#123;</span>
<span style="color: #008000;"># Check the host name and exit if the host is not the Windows PowerShell console host.</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$host</span>.Name <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">'ConsoleHost'</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #008080; font-weight: bold;">write-host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Red <span style="color: #800000;">&quot;This script runs only in the console host. You cannot run this script in $($host.Name).&quot;</span>
  exit <span style="color: pink;">-</span><span style="color: #000000;">1</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Initialize string builder.</span>
<span style="color: #800080;">$textBuilder</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> system.text.stringbuilder
&nbsp;
<span style="color: #008000;"># Grab the console screen buffer contents using the Host console API.</span>
<span style="color: #800080;">$bufferWidth</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.ui.rawui.BufferSize.Width
<span style="color: #800080;">$bufferHeight</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.ui.rawui.CursorPosition.Y
<span style="color: #800080;">$rec</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> System.Management.Automation.Host.Rectangle <span style="color: #000000;">0</span><span style="color: pink;">,</span><span style="color: #000000;">0</span><span style="color: pink;">,</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$bufferWidth</span> <span style="color: pink;">-</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #800080;">$bufferHeight</span>
<span style="color: #800080;">$buffer</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.ui.rawui.GetBufferContents<span style="color: #000000;">&#40;</span><span style="color: #800080;">$rec</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;"># Iterate through the lines in the console buffer.</span>
<span style="color: #0000FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: pink;">=</span> <span style="color: #000000;">0</span>; <span style="color: #800080;">$i</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$bufferHeight</span>; <span style="color: #800080;">$i</span><span style="color: pink;">++</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #0000FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$j</span> <span style="color: pink;">=</span> <span style="color: #000000;">0</span>; <span style="color: #800080;">$j</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$bufferWidth</span>; <span style="color: #800080;">$j</span><span style="color: pink;">++</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #800080;">$cell</span> <span style="color: pink;">=</span> <span style="color: #800080;">$buffer</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$i</span><span style="color: pink;">,</span><span style="color: #800080;">$j</span><span style="color: #000000;">&#93;</span>
    <span style="color: #800080;">$null</span> <span style="color: pink;">=</span> <span style="color: #800080;">$textBuilder</span>.Append<span style="color: #000000;">&#40;</span><span style="color: #800080;">$cell</span>.Character<span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#125;</span>
  <span style="color: #800080;">$null</span> <span style="color: pink;">=</span> <span style="color: #800080;">$textBuilder</span>.Append<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span>&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">return</span> <span style="color: #800080;">$textBuilder</span>.ToString<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">################################################################</span>
&nbsp;
<span style="color: #008000;"># Pause Script</span>
<span style="color: #0000FF;">function</span> Pause <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Message</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Script Complete. Press any key to continue...&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-NoNewLine</span> <span style="color: #800080;">$Message</span>
<span style="color: #800080;">$null</span> <span style="color: pink;">=</span> <span style="color: #000080;">$Host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;&quot;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">################################################################</span>
&nbsp;
<span style="color: #0000FF;">function</span> Get<span style="color: pink;">-</span>UserProfileConfigManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$siteUrl</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #008000;"># Need to get a PortalContext object</span>
<span style="color: #008000;"># as we do not have a HttpContext we need to source one the hard way</span>
<span style="color: #800080;">$site</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.SharePoint.SPSite<span style="color: #000000;">&#40;</span><span style="color: #800080;">$siteUrl</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$servercontext</span><span style="color: pink;">=</span><span style="color: #000000;">&#91;</span>Microsoft.Office.Server.ServerContext<span style="color: #000000;">&#93;</span>::GetContext<span style="color: #000000;">&#40;</span><span style="color: #800080;">$site</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$site</span>.Dispose<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;"># clean up</span>
&nbsp;
<span style="color: #008000;">################################################################</span>
&nbsp;
<span style="color: #008000;"># Return the UserProfileConfigManager</span>
<span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.Office.Server.UserProfiles.UserProfileConfigmanager<span style="color: #000000;">&#40;</span><span style="color: #800080;">$servercontext</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">function</span> Get<span style="color: pink;">-</span>SPProfileManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$siteUrl</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #008000;"># Need to get a PortalContext object</span>
<span style="color: #008000;"># as we do not have a HttpContext we need to source one the hard way</span>
<span style="color: #800080;">$site</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.SharePoint.SPSite<span style="color: #000000;">&#40;</span><span style="color: #800080;">$siteUrl</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$servercontext</span><span style="color: pink;">=</span><span style="color: #000000;">&#91;</span>Microsoft.Office.Server.ServerContext<span style="color: #000000;">&#93;</span>::GetContext<span style="color: #000000;">&#40;</span><span style="color: #800080;">$site</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$site</span>.Dispose<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;"># clean up</span>
&nbsp;
<span style="color: #008000;">################################################################</span>
&nbsp;
<span style="color: #008000;"># Return the UserProfileManager</span>
<span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.Office.Server.UserProfiles.UserProfileManager<span style="color: #000000;">&#40;</span><span style="color: #800080;">$servercontext</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">function</span> Get<span style="color: pink;">-</span>SPUserProfile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$siteUrl</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$u</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$upm</span><span style="color: pink;">=</span> Get<span style="color: pink;">-</span>SPProfileManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$siteUrl</span><span style="color: #000000;">&#41;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$upm</span>.UserExists<span style="color: #000000;">&#40;</span><span style="color: #800080;">$u</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$false</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #800080;">$upm</span>.CreateUserProfile<span style="color: #000000;">&#40;</span><span style="color: #800080;">$u</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$upm</span>.GetUserProfile<span style="color: #000000;">&#40;</span><span style="color: #800080;">$u</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">################################################################</span>
&nbsp;
<span style="color: #008000;"># Create function</span>
<span style="color: #0000FF;">function</span> Update<span style="color: pink;">-</span>UserProfileProperty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">PARAM</span>
	<span style="color: #000000;">&#40;</span>
		<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$siteUrl</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span> <span style="color: #0000FF;">throw</span> <span style="color: #800000;">&quot;You must provide a Site Collection Url e.g. 'http://moss/'&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span>
		<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$userName</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span> <span style="color: #0000FF;">throw</span> <span style="color: #800000;">&quot;You must provide a User Name e.g. 'DOMAIN\USERNAME'&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span>
		<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$propName</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span> <span style="color: #0000FF;">throw</span> <span style="color: #800000;">&quot;You must provide a User Profile Property Name e.g. 'WorkPhone'&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span>
		<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$propValue</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span> <span style="color: #0000FF;">throw</span> <span style="color: #800000;">&quot;You must provide a User Profile Property Value e.g. '0400 767 022'&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#41;</span>
	END
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$propValue</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;NULL&quot;</span> <span style="color: #FF0000;">-or</span> <span style="color: #800080;">$propValue</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;&quot;</span> <span style="color: #FF0000;">-or</span> <span style="color: #800080;">$propValue</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;None&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Property '$propName' is not set ('$propValue')&quot;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0000FF;">else</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$cm</span> <span style="color: pink;">=</span> get<span style="color: pink;">-</span>userprofileconfigmanager <span style="color: #800080;">$siteUrl</span>
			<span style="color: #800080;">$spm</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>SPProfileManager <span style="color: #800080;">$siteUrl</span>
			<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$spm</span>.UserExists<span style="color: #000000;">&#40;</span><span style="color: #800080;">$userName</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #800080;">$userProfile</span> <span style="color: pink;">=</span> <span style="color: #800080;">$spm</span>.GetUserProfile<span style="color: #000000;">&#40;</span><span style="color: #800080;">$userName</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #800080;">$tempProp</span> <span style="color: pink;">=</span> <span style="color: #800080;">$spm</span>.Properties.GetPropertyByName<span style="color: #000000;">&#40;</span><span style="color: #800080;">$propName</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$tempProp</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					<span style="color: #0000FF;">throw</span> <span style="color: #800000;">&quot;User Profile Property '$propName' does not exist!&quot;</span>;
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0000FF;">else</span>
				<span style="color: #000000;">&#123;</span>
					<span style="color: #800080;">$userProfile</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$propName</span><span style="color: #000000;">&#93;</span>.Value <span style="color: pink;">=</span> <span style="color: #800080;">$propValue</span>;
					<span style="color: #800080;">$userProfile</span>.Commit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
				<span style="color: #008080; font-weight: bold;">write-host</span> <span style="color: #008080; font-style: italic;">-foregroundcolor</span> green <span style="color: #800000;">&quot;'$propName' User Profile Property updated to '$propValue' for '$userName'&quot;</span>
				<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">&quot;'$propName' User Profile Property updated to '$propValue' for '$userName'&quot;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0000FF;">else</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> red  <span style="color: #800000;">&quot;User '$userName' does not exist in User Profiles!&quot;</span>
				<span style="color: #008080; font-weight: bold;">Write-output</span> <span style="color: #800000;">&quot;User '$userName' does not exist in User Profiles!&quot;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">################################################################</span>
&nbsp;
<span style="color: #0000FF;">function</span> MySiteProUpdate<span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$username</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;IB\Admin&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;IB\Guest&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;IB\PowerShell&quot;</span>
&nbsp;
<span style="color: #008000;"># Set MySite URL</span>
<span style="color: #800080;">$siteUrl</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;http://mysites:3000&quot;</span>
&nbsp;
<span style="color: #008000;"># Notifies</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Working... Please Wait&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">&quot; &quot;</span>
&nbsp;
<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;">$username</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
<span style="color: #008000;"># Executes command for all users in this script</span>
<span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800000;">&quot;Executing this command :  Update-UserProfileProperty $siteUrl $u ActiveEmployee true&quot;</span>
Update<span style="color: pink;">-</span>UserProfileProperty <span style="color: #800080;">$siteUrl</span> <span style="color: #800000;">&quot;$u&quot;</span> <span style="color: #800000;">&quot;ActiveEmployee&quot;</span> <span style="color: #800000;">&quot;true&quot;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #008000;"># Dump Console</span>
<span style="color: #800080;">$textFileName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;C:\IBLogs\ConsoleDump.txt&quot;</span>
Get<span style="color: pink;">-</span>ConsoleAsText <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-file</span> <span style="color: #800080;">$textFileName</span> <span style="color: #008080; font-style: italic;">-encoding</span> ascii
<span style="color: #008000;">#$null = [System.Diagnostics.Process]::Start(&quot;$textFileName&quot;)</span>
pause
<span style="color: #000000;">&#125;</span>
<span style="color: #008000;">################################################################</span>
&nbsp;
MySiteProUpdate <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-File</span> C:\IBLogs\Progress.txt</pre></td></tr></table></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.isaacblum.com%2F2010%2F01%2F21%2Fpowershell-bulk-update-moss-profile%2F&amp;linkname=PowerShell%20%26%238211%3B%20Bulk%20Update%20MOSS%20Profile"><img src="http://blog.isaacblum.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.isaacblum.com/2010/01/21/powershell-bulk-update-moss-profile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Pause</title>
		<link>http://blog.isaacblum.com/2009/12/31/powershell-pause/</link>
		<comments>http://blog.isaacblum.com/2009/12/31/powershell-pause/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 19:36:20 +0000</pubDate>
		<dc:creator>Isaac Blum</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[For The Greater Good]]></category>
		<category><![CDATA[Free Help]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[pause]]></category>

		<guid isPermaLink="false">http://blog.isaacblum.com/2009/12/31/powershell-pause/</guid>
		<description><![CDATA[Add the below code to any PowerShell script to call a pause. This code is made possible by http://blogs.msdn.com/powershell/archive/2007/02/25/pause.aspx 1 2 3 4 5 6 function Pause &#40;$Message=&#34;Press any key to continue...&#34;&#41; &#123; Write-Host -NoNewLine $Message $null = $Host.UI.RawUI.ReadKey&#40;&#34;NoEcho,IncludeKeyDown&#34;&#41; Write-Host &#34;&#34; &#125;]]></description>
			<content:encoded><![CDATA[<p>Add the below code to any PowerShell script to call a pause.</p>
<p>This code is made possible by http://blogs.msdn.com/powershell/archive/2007/02/25/pause.aspx</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> Pause <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Message</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Press any key to continue...&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-NoNewLine</span> <span style="color: #800080;">$Message</span>
<span style="color: #800080;">$null</span> <span style="color: pink;">=</span> <span style="color: #000080;">$Host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;&quot;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.isaacblum.com%2F2009%2F12%2F31%2Fpowershell-pause%2F&amp;linkname=PowerShell%20Pause"><img src="http://blog.isaacblum.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.isaacblum.com/2009/12/31/powershell-pause/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Join Domain Power Shell Script</title>
		<link>http://blog.isaacblum.com/2009/09/29/join-domain-power-shell-script/</link>
		<comments>http://blog.isaacblum.com/2009/09/29/join-domain-power-shell-script/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 03:19:49 +0000</pubDate>
		<dc:creator>Isaac Blum</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[For The Greater Good]]></category>
		<category><![CDATA[Free Help]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Add to Groups PowerShell]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[Join Domain]]></category>
		<category><![CDATA[Join Domain PowerShell]]></category>
		<category><![CDATA[Launch SQL Script PowerShell]]></category>
		<category><![CDATA[ps1]]></category>
		<category><![CDATA[Reboot PowerShell]]></category>
		<category><![CDATA[Rename Computer PowerShell]]></category>

		<guid isPermaLink="false">http://blog.isaacblum.com/?p=117</guid>
		<description><![CDATA[While trying to create this script I came across a ton of help, Thanks online community’s!! Download file here 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 [...]]]></description>
			<content:encoded><![CDATA[<p>While trying to create this script I came across a ton of help, Thanks online community’s!!</p>
<p>Download file <a href="http://isaacblum.com/wp-content/uploads/2010/01/JoinDomain.ps1">here</a></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
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;">&nbsp;
<span style="color: #008000;"># Execute a SQL File Begin</span>
<span style="color: #0000FF;">function</span> Execute<span style="color: pink;">-</span>SqlFile<span style="color: #000000;">&#40;</span><span style="color: #800080;">$file</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Server</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$dbName</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">hashtable</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$variables</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">switch</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$WindowsAuthentication</span><span style="color: pink;">=</span><span style="color: #800080;">$true</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Username</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Password</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$batch</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">join-Path</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">cat</span> env:TEMP<span style="color: #000000;">&#41;</span> <span style="color: #800000;">&quot;exec_sql.bat&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #008080; font-weight: bold;">write-Host</span> Connecting to <span style="color: #800080;">$Server</span><span style="color: pink;">&lt;/</span>code<span style="color: pink;">&gt;</span>
&nbsp;
<span style="color: #800080;">$output</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">join-Path</span> <span style="color: #800080;">$env</span>:TEMP <span style="color: #800000;">&quot;output_sql.txt&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">test-Path</span> <span style="color: #800080;">$batch</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Remove-Item</span> <span style="color: #800080;">$batch</span> <span style="color: #008080; font-style: italic;">-force</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$data</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">test-Path</span> <span style="color: #800080;">$batch</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-weight: bold;">Remove-Item</span> <span style="color: #800080;">$batch</span> <span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$data</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;sqlcmd -S $Server&quot;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$WindowsAuthentication</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$data</span> <span style="color: pink;">+=</span> <span style="color: #800000;">' -E'</span>
<span style="color: #000000;">&#125;</span> <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$data</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot; -U $Username -P $Password&quot;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$dbname</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$data</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot; -d $dbName&quot;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$variables</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;">$variables</span>.Count <span style="color: #FF0000;">-gt</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$data</span> <span style="color: pink;">+=</span> <span style="color: #800000;">' -v '</span>
<span style="color: #800080;">$isFirst</span> <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$key</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$variables</span>.keys<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: pink;">!</span> <span style="color: #800080;">$isFirst</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$data</span> <span style="color: pink;">+=</span> <span style="color: #800000;">' '</span> <span style="color: #000000;">&#125;</span> <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$isFirst</span><span style="color: pink;">=</span><span style="color: #800080;">$false</span> <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #800080;">$val</span> <span style="color: pink;">=</span> <span style="color: #800080;">$variables</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$key</span><span style="color: #000000;">&#93;</span>
<span style="color: #800080;">$data</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;$key=&quot;</span>
<span style="color: #800080;">$data</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`&quot;</span>$val<span style="color: #008080; font-weight: bold;">`&quot;</span>&quot;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$data</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot; -i <span style="color: #008080; font-weight: bold;">`&quot;</span>$file<span style="color: #008080; font-weight: bold;">`&quot;</span>&quot;</span>
&nbsp;
<span style="color: #800080;">$data</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot; -o <span style="color: #008080; font-weight: bold;">`&quot;</span>$output<span style="color: #008080; font-weight: bold;">`&quot;</span>&quot;</span>
&nbsp;
<span style="color: #800080;">$data</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800080;">$batch</span> <span style="color: #008080; font-style: italic;">-force</span>
&nbsp;
cmd <span style="color: pink;">/</span>c <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Resolve-Path</span> <span style="color: #800080;">$batch</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-weight: bold;">gc</span> <span style="color: #800080;">$output</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #008000;"># Allows for a Pause Begin</span>
<span style="color: #0000FF;">function</span> Pause <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Message</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Press any key to continue...&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-NoNewLine</span> <span style="color: #800080;">$Message</span>
<span style="color: #800080;">$null</span> <span style="color: pink;">=</span> <span style="color: #000080;">$Host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;&quot;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #008000;"># Sets Variables By Asking The Users a Question Begin</span>
<span style="color: #800080;">$Yourfirstname</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;What is Your First Name? 5 characters Max &quot;</span>
<span style="color: #800080;">$yourrandomnumber</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;Random Number? Two Digits Max&quot;</span>
&nbsp;
&nbsp;
<span style="color: #008000;"># Hard Coded Variables Begin</span>
<span style="color: #800080;">$aspen</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;aspen-&quot;</span>
<span style="color: #800080;">$dash</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;-&quot;</span>
<span style="color: #800080;">$computer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;.&quot;</span>
&nbsp;
&nbsp;
<span style="color: #008000;"># Rename Computer EX: aspen-john-1  Begin</span>
<span style="color: #800080;">$computerobject</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">gwmi</span> <span style="color: #008080; font-style: italic;">-Class</span> Win32_ComputerSystem <span style="color: #008080; font-style: italic;">-Namespace</span> <span style="color: #800000;">&quot;root\cimv2&quot;</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computer</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$computerobject</span>.rename<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;$aspen$Yourfirstname$dash$yourrandomnumber&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #008000;"># Get the Conputers Name Begin</span>
<span style="color: #800080;">$comp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">get-wmiobject</span> Win32_ComputerSystem
&nbsp;
&nbsp;
<span style="color: #008000;"># Joings Computer to the Doamin Begin</span>
<span style="color: #008000;"># (&quot;%DomainName%&quot;,&quot;%Username'sPassword%&quot;,&quot;%DomainName\Username%&quot;,$null,3)</span>
<span style="color: #800080;">$comp</span>.JoinDomainOrWorkGroup<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;%%%%%&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;%%%%%&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;%%%%&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$null</span><span style="color: pink;">,</span><span style="color: #000000;">3</span><span style="color: #000000;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #008000;"># Calls another PowerShell Script To Set Permission Begin</span>
<span style="color: #008000;"># ./SetFolderPermission.ps1 -Access %Username% -Permission %PermisionLevel%</span>
.<span style="color: pink;">/</span>SetFolderPermission.ps1 <span style="color: pink;">-</span>Access <span style="color: pink;">%</span>DomainName<span style="color: pink;">%</span>\<span style="color: pink;">%</span>Username<span style="color: pink;">%</span> <span style="color: pink;">-</span>Permission FullControl
&nbsp;
&nbsp;
<span style="color: #008000;"># Hard Coded Variables Begin</span>
<span style="color: #800080;">$domain</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;%DomainName%&quot;</span>
<span style="color: #800080;">$strComputer</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">gc</span> env:computername
&nbsp;
&nbsp;
<span style="color: #008000;"># Sets Variables By Asking The Users a Question Begin</span>
<span style="color: #800080;">$username</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;What is Your Aspenware domain username without the %DomainName%\&quot;</span>
&nbsp;
&nbsp;
<span style="color: #008000;"># Adds User to Aministrators Group Begin</span>
<span style="color: #800080;">$computer</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>ADSI<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;WinNT://&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$strComputer</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;,computer&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$computer</span>.name
<span style="color: #800080;">$Group</span> <span style="color: pink;">=</span> <span style="color: #800080;">$computer</span>.psbase.children.find<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;administrators&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$Group</span>.name
<span style="color: #800080;">$Group</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;WinNT://&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$domain</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;/&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$username</span><span style="color: #000000;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #008000;"># Adds User to IIS_WPG Group Begin</span>
<span style="color: #800080;">$domain</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;%DomainName%&quot;</span>
<span style="color: #800080;">$strComputer</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">gc</span> env:computername
<span style="color: #800080;">$username</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;svcnj&quot;</span>
<span style="color: #800080;">$computer</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>ADSI<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;WinNT://&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$strComputer</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;,computer&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$computer</span>.name
<span style="color: #800080;">$Group</span> <span style="color: pink;">=</span> <span style="color: #800080;">$computer</span>.psbase.children.find<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;IIS_WPG&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$Group</span>.name
<span style="color: #800080;">$Group</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;WinNT://&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$domain</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;/&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$username</span><span style="color: #000000;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #008000;"># Executes a SQL Script to add User Account to the SQL Server with SYSAdmin  Begin</span>
Execute<span style="color: pink;">-</span>Sqlfile <span style="color: #800000;">&quot;C:\Documents and Settings\Administrator\svcnjsql.sql&quot;</span> <span style="color: #800080;">$computer</span>.name
&nbsp;
&nbsp;
<span style="color: #008000;"># Pause Then Reboots the Server Begin</span>
pause
<span style="color: #800080;">$reboot</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">gwmi</span> <span style="color: #008080; font-style: italic;">-Class</span> Win32_OperatingSystem<span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$reboot</span>.psbase.scope.options.enableprivileges <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>
<span style="color: #800080;">$reboot</span>.reboot<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.isaacblum.com%2F2009%2F09%2F29%2Fjoin-domain-power-shell-script%2F&amp;linkname=Join%20Domain%20Power%20Shell%20Script"><img src="http://blog.isaacblum.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.isaacblum.com/2009/09/29/join-domain-power-shell-script/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PowerShell Missing on Server 2008???!!!</title>
		<link>http://blog.isaacblum.com/2009/09/29/powershell-missing-on-server-2008/</link>
		<comments>http://blog.isaacblum.com/2009/09/29/powershell-missing-on-server-2008/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 22:47:12 +0000</pubDate>
		<dc:creator>Isaac Blum</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Free Help]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Server 2008]]></category>
		<category><![CDATA[Server 2008 Features]]></category>

		<guid isPermaLink="false">http://blog.isaacblum.com/?p=115</guid>
		<description><![CDATA[Steps Below. 1. Click Start and select Server Manager. 2. When the Server Manager window appears, go to the left pane and select Features. 3. On the right, click the Add Features link. 4. Scroll down the list and check the Windows PowerShell checkbox. 5. Click Next. 6. Click Install. 7. When the installation is [...]]]></description>
			<content:encoded><![CDATA[<p>Steps Below.</p>
<p>1. Click Start and select Server Manager.</p>
<p>2. When the Server Manager window appears, go to the left pane and select Features.</p>
<p>3. On the right, click the Add Features link.</p>
<p>4. Scroll down the list and check the Windows PowerShell checkbox.</p>
<p>5. Click Next.</p>
<p>6. Click Install.</p>
<p>7. When the installation is complete, Windows should display that the installation succeeded.</p>
<p>8. Click Close.</p>
<p>9. Close the Server Manager.</p>
<p>10. To open PowerShell, go to the Start Menu, click All Programs and expand the Windows PowerShell 1.0 folder to get to the shortcut to Windows PowerShell.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.isaacblum.com%2F2009%2F09%2F29%2Fpowershell-missing-on-server-2008%2F&amp;linkname=PowerShell%20Missing%20on%20Server%202008%3F%3F%3F%21%21%21"><img src="http://blog.isaacblum.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.isaacblum.com/2009/09/29/powershell-missing-on-server-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
