tag:blogger.com,1999:blog-3947194782137590082024-03-15T18:09:45.465-07:00IT BlogNetwork_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-394719478213759008.post-30772483185236643662016-08-10T01:32:00.000-07:002016-08-10T01:34:21.312-07:00IIS; 3 ways to redirect<span style="font-family: "arial" , "helvetica" , sans-serif;">Using IIS 8.5 there are three was to re-direct traffic to another location. In my case I needed to redirect traffic from one IIS site to another. Requirements for redirection are not always the same, and sometimes an individual page or file may need to be redirected. In all cases a variation of one of the examples below should be sufficient to redirect traffic in the way you need.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Method 1 HTTP ReDirect</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Redirect traffic using the HTTP Redirection feature.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Http Redirect should be the most simple method of redirecting traffic to another location, however in my case it caused the most confusion and led me to explore the other methods listed below. </span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">The Http Redirection feature must be installed before this method can be used.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">When adding a redirect rule using this method, the <b>system.webServer</b> section of the <b>web.config</b> file for the site is updated with the redirection rule. In my case I wanted to redirect traffic from <i>site1</i> to <i>site2</i>. However <i>site1</i> and <i>site2</i> were both sharing the same physical folder and site content. This meant that changing the HTTP Redirect setting for one changed it for both, leaving me with a situation where neither site was working.</span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">The extract below shows the <b>system.webServer</b> section of the <b>web.config</b> file updated with the <span style="color: #6fa8dc;"><httpRedirect></span> setting.</span><br />
<br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> <location </span><span style="color: red; font-family: "arial" , "helvetica" , sans-serif;">path</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;">=</span><b><span style="color: purple;">"www.mysite.co.uk"</span></b><span style="color: #3d85c6;">></span></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> <system.webServer></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> <security></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> <authentication></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> <anonymousAuthentication </span><span style="color: red; font-family: "arial" , "helvetica" , sans-serif;">userName</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;">=</span><b><span style="color: purple;">""</span></b><span style="color: #3d85c6;"> /></span></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> </authentication></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> <access </span><span style="color: red; font-family: "arial" , "helvetica" , sans-serif;">sslFlags</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;">=</span><b><span style="color: purple;">"Ssl"</span></b><span style="color: #3d85c6;"> /></span></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> </security></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span> <httpRedirect </span><span style="color: red; font-family: "arial" , "helvetica" , sans-serif;">enabled</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">=</span><span style="color: purple; font-family: "arial" , "helvetica" , sans-serif;"><b>"true"</b></span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> </span><span style="color: red; font-family: "arial" , "helvetica" , sans-serif;">destination</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;">=</span><b><span style="color: purple;">"https://www.myothersite.co.uk"</span></b> </span><span style="color: red; font-family: "arial" , "helvetica" , sans-serif;">exactDestination</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;">=</span><b><span style="color: purple;">"true"</span></b> </span><span style="color: red; font-family: "arial" , "helvetica" , sans-serif;">httpResponseStatus</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">=</span><span style="color: purple; font-family: "arial" , "helvetica" , sans-serif;"><b>"Permanent"</b></span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> /></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> </system.webServer></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> </location</span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">To get around this problem I moved the <httpRedirect> tag into the applicationHost.config file, (I suggest making a backup of applicationHost.config before making any changes)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">This is how I did it:</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">1. Open this file:</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>C:\Windows\System32\inetsrv\config\applicationHost.config</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">2. Search for www.mysite.co.uk</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">3. Scroll through the results until you see the result in the <location> element. </span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">4. Add the httpRedirect rule inside the system.webServer tags.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">It will probably look something like this:</span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;"><location </span><span style="color: red;">path</span><span style="color: #3d85c6;">=</span><b><span style="color: purple;">"www.mysite.co.uk"</span></b><span style="color: #3d85c6;">></span></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> <system.webServer></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> <security></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> <authentication></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;"> <anonymousAuthentication </span><span style="color: red;">userName</span><span style="color: #3d85c6;">=</span><b><span style="color: purple;">""</span></b><span style="color: #3d85c6;"> /></span></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> </authentication></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> <access </span><span style="color: red; font-family: "arial" , "helvetica" , sans-serif;">sslFlags</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">=</span><span style="color: purple; font-family: "arial" , "helvetica" , sans-serif;"><b>"Ssl"</b></span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> /></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> </security></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span class="Apple-tab-span" style="color: #3d85c6; white-space: pre;"> </span><span style="color: #3d85c6;"> <httpRedirect </span><span style="color: red;">enabled</span><span style="color: #3d85c6;">=</span><b><span style="color: purple;">"true"</span></b><span style="color: #3d85c6;"> </span><span style="color: red;">destination</span><span style="color: #3d85c6;">=</span><span style="color: purple;"><b>"https://www.myothersite.co.uk"</b></span><span style="color: #3d85c6;"> </span><span style="color: red;">exactDestination</span><span style="color: #3d85c6;">=</span><b><span style="color: purple;">"true"</span></b><span style="color: #3d85c6;"> </span><span style="color: red;">httpResponseStatus</span><span style="color: #3d85c6;">=</span><b><span style="color: purple;">"Permanent"</span></b><span style="color: #3d85c6;"> /></span></span><br />
<span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;"> </system.webServer></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;"></location></span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">You can then delete <b>httpRedirect</b> out of the <b>web.config</b> file.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Redirecting is much simpler using the IIS Management Console, and can be done like this:</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Select whatever it is you want to redirect, then double click <b>HTTP Redirect</b> (make sure <i>Features View</i> is enabled)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3MG_hFarhxLgPxIclcmkfgxQljFa1RhbupnXbFFAkPwd6zi-DjlIebE_59m53CDXYe6EvM86xAqIu63_Hs-bF-Rsj4fwltQjn6550u9pMZunaZnM45XLLNVoUysf2iB4LO6TN4jtvLso/s1600/IISRedir001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="192" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3MG_hFarhxLgPxIclcmkfgxQljFa1RhbupnXbFFAkPwd6zi-DjlIebE_59m53CDXYe6EvM86xAqIu63_Hs-bF-Rsj4fwltQjn6550u9pMZunaZnM45XLLNVoUysf2iB4LO6TN4jtvLso/s320/IISRedir001.jpg" width="320" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">You can then enable redirection by ticking the "Redirect requests to this destination" box and clicking Apply. </span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBHF5VstkTzBZT4N8nHHAa1bnuBDAAKQsQRXVReHD2dYEgRJliYCwaObEdH5b5IMAWaYFa2cYTVBe248N5Aa6jCbKupC7JeYtrpSwZ-2Kpzh6rOSeJhNPO0hcliutyzXaf8s3IUibOTd0/s1600/IISRedir002.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="184" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBHF5VstkTzBZT4N8nHHAa1bnuBDAAKQsQRXVReHD2dYEgRJliYCwaObEdH5b5IMAWaYFa2cYTVBe248N5Aa6jCbKupC7JeYtrpSwZ-2Kpzh6rOSeJhNPO0hcliutyzXaf8s3IUibOTd0/s320/IISRedir002.jpg" width="320" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Method 2 Bindings</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Redirect traffic by changing the site bindings</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">The site Bindings tell IIS which site should receive the traffic it is to process. A single site can have many different bindings, and as long as traffic is routed correctly to the server it will be processed by IIS and passed to the relevant site.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">If I want to redirect traffic for <i>site1</i> to <i>site2</i>, I can add the binding for <i>site1</i> to <i>site2</i>. See below for an example</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvUCNsSnuVA-ChS2MID69DW_GUi0t-5Omts0SLSVIbxaMaOlemY45rJiH_KXDzRpiEeKTyeEFoi9EGIlCGHcSoZ8Oioi2zgRKqvW_kFQV6BlFXMJGJuQfpsQx52u7xzxw2KyjqN4_cDJA/s1600/IISRedir003.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="174" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvUCNsSnuVA-ChS2MID69DW_GUi0t-5Omts0SLSVIbxaMaOlemY45rJiH_KXDzRpiEeKTyeEFoi9EGIlCGHcSoZ8Oioi2zgRKqvW_kFQV6BlFXMJGJuQfpsQx52u7xzxw2KyjqN4_cDJA/s320/IISRedir003.jpg" width="320" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">In this example the site will receive traffic for both www.mysite.co.uk and www.myothersite.co.uk (as long as the public dns record exists and is routing to the server).</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">One thing to note is that each site binding must be unique. Two identical bindings on different sites will cause an error in IIS meaning only one of the sites can be started.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">For this example it is not necessary for the other sites to exist in IIS, only the binding is required for the data to reach the site.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-size: large;">Method 3 URL ReWrite</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Redirect traffic using the URL Rewrite module.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">This is the most difficult and complicated method of redirecting traffic, however it is also the most flexible.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">There are a lot of resources available for the URL Rewrite module, but I found <a href="http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference" target="_blank">this page</a> to be the most useful.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">URL Rewrite can be be used to accomplish multiple different tasks, so to keep things simple I will only describe how I used it to redirect traffic from one site to another.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>Step 1</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Install <a href="https://www.iis.net/downloads/microsoft/url-rewrite" target="_blank">URL Rewrite module</a></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Once installed, the URL Rewrite module is available from the IIS Management Console in Features View.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixZVceMAZQPAnrp2VqlKnL-waFJld0bB-Weil-BZw_pE1Vb1Cn-J2ikX_F5S5TtISTD7FYw9Rk7L80psJYNANLEssy_EdPFCN5GKTR1U4uRd0PUXiK8yOP15KKNne6Z2jqcS9D8XrRttc/s1600/IISRedir004.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixZVceMAZQPAnrp2VqlKnL-waFJld0bB-Weil-BZw_pE1Vb1Cn-J2ikX_F5S5TtISTD7FYw9Rk7L80psJYNANLEssy_EdPFCN5GKTR1U4uRd0PUXiK8yOP15KKNne6Z2jqcS9D8XrRttc/s320/IISRedir004.jpg" width="320" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>Step 2</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Create a Rewrite rule</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">There are two types of scope:</span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>Global</b> -</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> will edit the applicationHost.config file using the <rewrite> tag, and will affect all traffic to all sites</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>Rule</b> - can be defined on any other level. From the documentation <i>"</i></span><span style="font-family: "arial" , "helvetica" , sans-serif;"><i>This type of rule can be added on any configuration level by using Web.config files or by using <location> tags within ApplicationHost.config or Web.config files."</i></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">I used a global rule, and added a condition that matches the site(s) I wanted to redirect.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">1. Open the URL Rewrite module</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">2. Select Add Rule(s)... > Blank Rule</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">3. Give the rule a name</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">4. Match URL</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">This section is used to match anything after the host part of the site address, as shown below</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Http://www.mysite.co.uk/<i>MatchURL</i></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">I want to redirect every request for the site, so I'm matching everything. The setting for this is:</span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Requested URL = Matches the Pattern</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Using = Regular Expressions</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Pattern = (.*)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">The data matched here can be used for rewriting and redirecting using a process known as back-references. Back-references to rule patterns are identified by {R:N} where N is from 0 to 9. The match here would be represented by {R:0}. If the regular expression produced multiple results, they would be represented by {R:1} and so on.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">5. Conditions</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Conditions are optional. They allow filtering based on the host part of the site address, so I am using conditions to identify the parts of the address to be redirected.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Logical grouping = Match All/Match Any (depending on requirements)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Select <b>Add</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Condition input = {HTTP_HOST}</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Check if input string: = Matches the Pattern</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Pattern: = ^(www\.)(.*)$</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Ignor case = ticked</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Clicking <b>Test Pattern</b> allows us to test the regular expression and discover how the back references will be used.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVSKaAgmv6w_Dw3_myuKfttnAobP0-AGswOOigzOBn45IqOyvXK7NIy-6D6hoR_SIdiGIBQlsNubqZKnt3TlRpiqDDtzse1o19Sb_iwL2-fIi3JSiUqGfr8YqDH0EX_qxfxqCp2b3lZPw/s1600/IISRedir005.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVSKaAgmv6w_Dw3_myuKfttnAobP0-AGswOOigzOBn45IqOyvXK7NIy-6D6hoR_SIdiGIBQlsNubqZKnt3TlRpiqDDtzse1o19Sb_iwL2-fIi3JSiUqGfr8YqDH0EX_qxfxqCp2b3lZPw/s320/IISRedir005.jpg" width="300" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">Back-references to condition patterns are identified by {C:N} where N is from 0 to 9. This can be seen in the image above. To redirect the site to new.mysite.co.uk we can now create a redirect action using http://new.{C:2}</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">To redirect the site to www.myothersite.co.uk we can create a redirect action using http://{C:1}myothersite.co.uk</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">To filter the rule to apply to certain sites, we can create additional conditions</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7FnGIYqz-c4PRF0S6gf-BTr_7q9ZmXEUiZVcybA_JiWUFhg9KODAUK2Cve9ItjSfjRNhWp0Wlr4Q47KCy7Qq0I5v0LgFRlf8xaMXjhBRotaQ22-r4Dl5JvQ9gg9QrvbPECIl0Ul7SZRA/s1600/IISRedir006.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7FnGIYqz-c4PRF0S6gf-BTr_7q9ZmXEUiZVcybA_JiWUFhg9KODAUK2Cve9ItjSfjRNhWp0Wlr4Q47KCy7Qq0I5v0LgFRlf8xaMXjhBRotaQ22-r4Dl5JvQ9gg9QrvbPECIl0Ul7SZRA/s320/IISRedir006.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-family: "arial" , "helvetica" , sans-serif;">The condition above will only apply to www.mysite.co.uk</span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">The combination of regular expression matching and back references provide an unlimited number of combinations for matching a redirecting.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">References</span>
<span style="font-family: "arial" , "helvetica" , sans-serif;">http://www.andrewwestgarth.co.uk/blog/post/2008/07/31/creating-http-redirects-in-iis7-on-virtual-directories-like-iis6.aspx</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">https://www.stokia.com/support/misc/web-config-response-redirect.aspx</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">https://www.iis.net/configreference/system.webserver/httpredirect</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com2tag:blogger.com,1999:blog-394719478213759008.post-43404818243455182172016-02-12T09:02:00.000-08:002016-02-12T09:02:47.657-08:00Automating IIS App Pool Compliance
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Background<o:p></o:p></span></b></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">With many servers comes the need to simply configuration
management. I find application pools to be a constant source of headaches when
it comes to keeping things consistent. They have loads of settings, which often
get changed when trying to troubleshoot a problem (and not changed back).
There’s also many other situations where they need to be configured; moving an
application to another server, operating system upgrades, migrations,
rationalisation, enforcing consistency - to name a few. <o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">This has led me to automate the process of app pool
configuration.<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">There are two scenarios to be covered – an ‘Online’ and an
‘Offline’ version. The Online version uses PowerShell remoting to connect to
another IIS server that contains all the app pools and their required
configurations. It then takes those settings and applies them to the target
server.<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">The Offline version uses an existing IIS server and exports
the app pool settings to a csv file, and then uses that to apply the settings
to a target server.<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Note that this process does not cover how to create app
pools. This can easily be done by using MS Web Deploy if migrating a site, or
New-WebAppPool if setting up a new site.<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">The process only works for IIS versions 7 and above. It
is possible to migrate app pool settings from IIS v6 to IIS v7 onwards but it
is more complicated than the process described here. The app pool settings are
not the same between these versions, plus standard PowerShell commands and the
IIS: drive are not available due to the limitations of PowerShell v2 (which is
the highest version that can be used on an IIS 6.0 server).<o:p></o:p></span></div>
<br />
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Preparation<o:p></o:p></span></b></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">The first step is to decide which settings need to be
configured. I like to set my app pool defaults first, and then explicitly set
anything which hasn’t been caught by the default settings. <o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Setting the app pool defaults will change any app pool
setting that isn’t the same as the new default setting or hasn’t been explicitly
set, so use with caution. Setting app pool defaults is usually a one off
setting when the server is new, or for a new global setting where there is a
requirement to overwrite all existing settings.<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">To keep things simple I won’t go into the details of how
to set app pool defaults, what I use for defaults, and how to revert an
explicit app pool setting to inherit the default, I’ll try and cover that in a
future blog post. <o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">For now, what is important is that I want to set some app
pool settings to a value that is different to the default.<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">The following settings need to be assessed as they may
need to be different to the defaults:<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">.NET CLR Version<o:p></o:p></span></div>
<span style="font-family: Calibri;">Enable 32 bit Applications<o:p></o:p></span><br />
<span style="font-family: Calibri;">Managed Pipeline Mode<o:p></o:p></span><br />
<span style="font-family: Calibri;">Identity<o:p></o:p></span><br />
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">I also want to change the Recycling > Specific Times
setting. My default is to recycle at 02:00am every day. I want to change this
so that each app pool recycles at a random time between 02:00 – 02:59. I
already have a separate script for this, see <a href="http://network-nick.blogspot.co.uk/2014/05/use-powershell-to-set-random-periodic.html" target="_blank">here</a> for a blog post.<o:p></o:p></span></div>
<o:p><span style="font-family: Calibri;"> </span></o:p><br />
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Offline Mode –
export<o:p></o:p></span></b></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">This method uses an existing IIS server and exports the
app pool settings to a csv file, and then uses that to apply the settings to a
target server.<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">The following script is used to obtain and export these
settings to csv file. <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">Import-Module</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: blueviolet;">webadministration</span><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">$AppPoolProperties</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">=</span> @()<o:p></o:p></span></div>
<span style="color: darkblue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"></span><br />
<span style="color: darkblue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">foreach</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> ( <span style="color: orangered;">$pool</span>
<span style="color: darkblue;">in</span> (<span style="color: blue;">get-item</span>
<span style="color: blueviolet;">IIS:\AppPools\*</span>) ) {<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">$Properties</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">=</span> <span style="color: blue;">New-Object</span> <span style="color: blueviolet;">System.Object</span><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">$Properties</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">|</span> <span style="color: blue;">Add-Member</span> <span style="color: navy;">-type</span> <span style="color: blueviolet;">NoteProperty</span>
<span style="color: navy;">-name</span> <span style="color: blueviolet;">AppPoolName</span>
`<o:p></o:p></span></div>
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"><span style="mso-spacerun: yes;"> </span><span style="color: navy;">-Value</span> $(<span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>name)<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">$Properties</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">|</span> <span style="color: blue;">Add-Member</span> <span style="color: navy;">-type</span> <span style="color: blueviolet;">NoteProperty</span>
<span style="color: navy;">-name</span> <span style="color: blueviolet;">Enable32bit</span>
`<o:p></o:p></span></div>
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"><span style="mso-spacerun: yes;"> </span><span style="color: navy;">-Value</span> $(<span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>enable32BitAppOnWin64)<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">$Properties</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">|</span> <span style="color: blue;">Add-Member</span> <span style="color: navy;">-type</span> <span style="color: blueviolet;">NoteProperty</span>
<span style="color: navy;">-name</span> <span style="color: blueviolet;">Runtime</span>
`<o:p></o:p></span></div>
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"><span style="mso-spacerun: yes;"> </span><span style="color: navy;">-Value</span> $(<span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>managedRuntimeVersion)<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">$Properties</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">|</span> <span style="color: blue;">Add-Member</span> <span style="color: navy;">-type</span> <span style="color: blueviolet;">NoteProperty</span>
<span style="color: navy;">-name</span> <span style="color: blueviolet;">Pipeline</span>
`<o:p></o:p></span></div>
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"><span style="mso-spacerun: yes;"> </span><span style="color: navy;">-Value</span> $(<span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>managedPipelineMode)<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">$Properties</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">|</span> <span style="color: blue;">Add-Member</span> <span style="color: navy;">-type</span> <span style="color: blueviolet;">NoteProperty</span>
<span style="color: navy;">-name</span> <span style="color: blueviolet;">ProcessModel</span>
`<o:p></o:p></span></div>
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"><span style="mso-spacerun: yes;"> </span><span style="color: navy;">-Value</span> $(<span style="color: orangered;">$pool</span> <span style="color: darkgrey;">|</span> <span style="color: blue;">Get-ItemProperty</span> <span style="color: navy;">-name</span>
<span style="color: blueviolet;">processModel.identityType</span>)<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">$AppPoolProperties</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">+=</span> <span style="color: orangered;">$Properties</span><o:p></o:p></span></div>
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">}<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">$AppPoolProperties</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">|</span> <span style="color: blue;">Export-Csv</span> <span style="color: blueviolet;">D:\AppPools.csv</span> <span style="color: navy;">-NoTypeInformation
<o:p></o:p></span></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;"></span></b> </div>
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Breakdown<o:p></o:p></span></b></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Import-Module WebAdministration<o:p></o:p></span></div>
<span style="font-family: Calibri;">This loads the WebAdministration module which is required
to make the IIS: drive available.<o:p></o:p></span><br />
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> $AppPoolProperties = @()<o:p></o:p></span></div>
<span style="font-family: Calibri;">Creates an empty variable called AppPoolProperties and
declares it as an array<o:p></o:p></span><br />
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Foreach loop<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> foreach ( $pool in (get-item IIS:\AppPools\*) )<o:p></o:p></span></div>
<span style="font-family: Calibri;"></span><br />
<span style="font-family: Calibri;">$pool is a
temporary variable that only exists in the loop. This variable represents each
member of the second command in the brackets –<o:p></o:p></span><br />
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"><span style="mso-spacerun: yes;"> </span>(get-item
IIS:\AppPools\*)<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">This returns a list of app pool objects, so $pool will
represent each app pool object in turn.<o:p></o:p></span></div>
<span style="font-family: Calibri;"></span><br />
<span style="font-family: Calibri;"> $Properties = New-Object System.Object<o:p></o:p></span><br />
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Creates a new temporary object, see this link for an
excellent explanation of custom objects:<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<a href="http://social.technet.microsoft.com/wiki/contents/articles/7804.powershell-creating-custom-objects.aspx"><span style="color: blue; font-family: Calibri;">http://social.technet.microsoft.com/wiki/contents/articles/7804.powershell-creating-custom-objects.aspx</span></a><o:p></o:p></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">The next section creates a variable for each of the app
pool settings I want. This is generally straightforward and can be done by
using $pool.property<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> $pool.enable32BitAppOnWin64<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">To see all the app pool properties available use <o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> get-item IIS:\AppPools\* | Select-Object –first 1|
Format-List –property *<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<strong><span style="font-family: "Calibri","sans-serif"; font-weight: normal; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Some of
the properties cannot be obtained by using $pool.property<o:p></o:p></span></strong></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<strong><span style="font-family: "Calibri","sans-serif"; font-weight: normal; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">ProcessModel
is an object type Microsoft.IIs.PowerShell.Framework.ConfigurationElement<o:p></o:p></span></strong></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<strong><span style="font-family: "Calibri","sans-serif"; font-weight: normal; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">To get its
value I have to use Get-ItemProperty. This command will return the Identity
Type for Process Model<o:p></o:p></span></strong></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> $pool | Get-ItemProperty -name processModel.identityType<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Next I need to create on object that has each app pool
value as a property. I use Add-Member to assign each of the app pool properties
to the $properties object. Piping the $properties object created earlier to
Add-Member assigns a name and value for each app pool property.<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Viewing the $properties object after adding the
properties for a single app pool looks like this<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">PS D:\scripts\modules> $Properties<o:p></o:p></span></div>
<span style="font-family: Calibri;">AppPoolName<span style="mso-spacerun: yes;"> </span>: .NET
v2.0 Classic<o:p></o:p></span><br />
<span style="font-family: Calibri;">Enable32bit<span style="mso-spacerun: yes;"> </span>:
False<o:p></o:p></span><br />
<span style="font-family: Calibri;">Runtime<span style="mso-spacerun: yes;"> </span>: v2.0<o:p></o:p></span><br />
<span style="font-family: Calibri;">Pipeline<span style="mso-spacerun: yes;"> </span>:
Classic<o:p></o:p></span><br />
<span style="font-family: Calibri;">ProcessModel : ApplicationPoolIdentity<o:p></o:p></span><br />
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> $AppPoolProperties += $Properties<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Finally the $properties object is added to the
$AppPoolProperties variable, and each time the foreach loop runs, another set
of app pool properties are added to this variable. Using += adds the current
object to the variable rather than overwriting the existing contents of the
variable.<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Once the loop is complete the final command uses
Export-CSV to write $AppPoolProperties to CSV<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> $AppPoolProperties | Export-Csv -Path D:\AppPools.csv –NoTypeInformation<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Copy the CSV file to your target server, then run the
Import script.<br clear="all" style="page-break-before: always;" />
<b style="mso-bidi-font-weight: normal;"></b></span></div>
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<strong><span style="font-family: Calibri;"></span></strong> </div>
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"><b style="mso-bidi-font-weight: normal;"></b></span> </div>
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"><b style="mso-bidi-font-weight: normal;">Offline Mode - import<o:p></o:p></b></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">The following script uses the exported CSV file to set
each app pool property. It takes the App Pool name, and looks for a matching
app pool, then sets the properties according to the setting in the CSV file. Once the app pool settings are in the CSV file, and the CSV file is stored on the server, this script can be run as a one off, or repeatedly to enforce the settings that are stored in the CSV file.</span></div>
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
</div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">Import-Module</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: blueviolet;">webadministration</span><o:p></o:p></span></div>
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"></span><br />
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">$AppPools</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">=</span> (<span style="color: blue;">Import-Csv</span> <span style="color: blueviolet;">D:\AppPools.csv</span>)<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: darkblue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">foreach</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> ( <span style="color: orangered;">$pool</span>
<span style="color: darkblue;">in</span> ( <span style="color: blue;">Get-Item</span>
<span style="color: blueviolet;">IIS:\AppPools\*</span> )) {<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">Set-ItemProperty</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: blueviolet;">IIS:\AppPools\</span>$(<span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>name) <span style="color: navy;">-Name</span> <span style="color: blueviolet;">enable32BitAppOnWin64</span> <span style="color: navy;">-Value</span>
`<o:p></o:p></span></div>
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"><span style="mso-spacerun: yes;"> </span><span style="color: darkred;">"</span>$(<span style="color: orangered;">$AppPools</span><span style="color: darkred;"> </span><span style="color: darkgrey;">|</span><span style="color: darkred;"> </span><span style="color: blue;">where</span><span style="color: darkred;"> </span>{<span style="color: darkred;"> </span><span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>AppPoolName<span style="color: darkred;"> </span><span style="color: darkgrey;">-eq</span><span style="color: darkred;"> </span><span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>name<span style="color: darkred;"> </span>}<span style="color: darkred;"> </span><span style="color: darkgrey;">|</span><span style="color: darkred;"> </span><span style="color: blue;">Select-Object</span><span style="color: darkred;"> </span><span style="color: navy;">-ExpandProperty</span><span style="color: darkred;"> </span><span style="color: blueviolet;">Enable32bit</span>)<span style="color: darkred;">"</span><o:p></o:p></span><br />
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span><br />
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">Set-ItemProperty</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: blueviolet;">IIS:\AppPools\</span>$(<span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>name) <span style="color: navy;">-Name</span> <span style="color: blueviolet;">managedRuntimeVersion</span> <span style="color: navy;">-Value</span>
`<o:p></o:p></span><br />
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"><span style="mso-spacerun: yes;"> </span><span style="color: darkred;">"</span>$(<span style="color: orangered;">$AppPools</span><span style="color: darkred;"> </span><span style="color: darkgrey;">|</span><span style="color: darkred;"> </span><span style="color: blue;">where</span><span style="color: darkred;"> </span>{<span style="color: darkred;"> </span><span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>AppPoolName<span style="color: darkred;"> </span><span style="color: darkgrey;">-eq</span><span style="color: darkred;"> </span><span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>name<span style="color: darkred;"> </span>}<span style="color: darkred;"> </span><span style="color: darkgrey;">|</span><span style="color: darkred;"> </span><span style="color: blue;">Select-Object</span><span style="color: darkred;"> </span><span style="color: navy;">-ExpandProperty</span><span style="color: darkred;"> </span><span style="color: blueviolet;">Runtime</span>)<span style="color: darkred;">"</span><o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">Set-ItemProperty</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: blueviolet;">IIS:\AppPools\</span>$(<span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>name) <span style="color: navy;">-Name</span> <span style="color: blueviolet;">managedPipelineMode</span> <span style="color: navy;">-Value</span>
`<o:p></o:p></span></div>
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"><span style="mso-spacerun: yes;"> </span><span style="color: darkred;">"</span>$(<span style="color: orangered;">$AppPools</span><span style="color: darkred;"> </span><span style="color: darkgrey;">|</span><span style="color: darkred;"> </span><span style="color: blue;">where</span><span style="color: darkred;"> </span>{<span style="color: darkred;"> </span><span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>AppPoolName<span style="color: darkred;"> </span><span style="color: darkgrey;">-eq</span><span style="color: darkred;"> </span><span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>name<span style="color: darkred;"> </span>}<span style="color: darkred;"> </span><span style="color: darkgrey;">|</span><span style="color: darkred;"> </span><span style="color: blue;">Select-Object</span><span style="color: darkred;"> </span><span style="color: navy;">-ExpandProperty</span><span style="color: darkred;"> </span><span style="color: blueviolet;">Pipeline</span>)<span style="color: darkred;">"</span><o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">Set-ItemProperty</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: blueviolet;">IIS:\AppPools\</span>$(<span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>name) <span style="color: navy;">-Name</span> <span style="color: blueviolet;">processModel.identityType</span> <span style="color: navy;">-Value</span> `<o:p></o:p></span></div>
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"><span style="mso-spacerun: yes;"> </span><span style="color: darkred;">"</span>$(<span style="color: orangered;">$AppPools</span><span style="color: darkred;"> </span><span style="color: darkgrey;">|</span><span style="color: darkred;"> </span><span style="color: blue;">where</span><span style="color: darkred;"> </span>{<span style="color: darkred;"> </span><span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>AppPoolName<span style="color: darkred;"> </span><span style="color: darkgrey;">-eq</span><span style="color: darkred;"> </span><span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>name<span style="color: darkred;"> </span>}<span style="color: darkred;"> </span><span style="color: darkgrey;">|</span><span style="color: darkred;"> </span><span style="color: blue;">Select-Object</span><span style="color: darkred;"> </span><span style="color: navy;">-ExpandProperty</span><span style="color: darkred;"> </span><span style="color: blueviolet;">ProcessModel</span>)<span style="color: darkred;">"</span><o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">}
<o:p></o:p></span></div>
<br />
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;"></span></b><br />
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Breakdown<o:p></o:p></span></b><br />
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> Import-Module WebAdministration<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">This loads the WebAdministration module which is required
to make the IIS: drive available.<o:p></o:p></span></div>
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"></span><br />
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> $AppPools</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> <span style="color: darkgrey;">=</span> (<span style="color: blue;">Import-Csv</span> <span style="color: blueviolet;">D:\AppPools.csv</span>)<o:p></o:p></span><br />
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Creates a variable from the contents of the CSV file<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">Foreach loop<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">This is the same as the previous script. The purpose is
to cycle through each local app pool, then change the settings accordingly. <o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> foreach ( $pool in (get-item IIS:\AppPools\*) )<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">The Set-ItemProperty command is quite long, so I will
break it down. <o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> Set-ItemProperty IIS:\AppPools\$($pool.name)<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">The item property to be set is defined as the app pool in
the current $pool variable, and is selected using the name property<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> -Name enable32BitAppOnWin64<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">The name parameter is the name of the property being
changed <o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;"> -Value<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing" style="margin: 0cm 0cm 0pt;">
<span style="font-family: Calibri;">For the Value parameter I obtain the app pool value stored
in the CSV file for the –name property<o:p></o:p></span></div>
<br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"> "$($AppPools | where { $_.AppPoolName -eq $pool.name } | Select-Object -ExpandProperty Runtime)"</span><br />
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"></span><br />
<span style="color: orangered; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> $AppPools<o:p></o:p></span><br />
<span style="font-family: Calibri;">Starts with the CSV contents in
the variable<o:p></o:p></span><br />
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"></span><br />
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> where</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">
{ <span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>AppPoolName
<span style="color: darkgrey;">-eq</span> <span style="color: orangered;">$pool</span><span style="color: darkgrey;">.</span>name }</span><o:p></o:p><br />
<span style="font-family: Calibri;">Filter with Where-Object to
select only the row in the CSV file that matches the current app pool ($pool
object) using the name property.<o:p></o:p></span><br />
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"></span><br />
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";"> Select-Object</span><span style="font-family: "Lucida Console"; font-size: 9pt; mso-bidi-font-family: "Lucida Console";">
<span style="color: navy;">-ExpandProperty</span> <span style="color: blueviolet;">Runtime</span><o:p></o:p></span><br />
<span style="font-family: Calibri;">Select the Property value with
Select-Object, in this case the Runtime value, which is the
managedRuntimeVersion</span><br />
<span style="font-family: Calibri;"></span><br />
<span style="font-family: Calibri;">The whole command is then wrapped in $(), this returns the contents of the value object rather than the object itself.<o:p></o:p></span><br />
<o:p><span style="font-family: Calibri;"></span></o:p><br />
<o:p></o:p><br />
<o:p><span style="font-family: Verdana, sans-serif;"><strong>Online mode - tbc ....</strong></span></o:p><br />
<o:p> </o:p><br />
Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com1tag:blogger.com,1999:blog-394719478213759008.post-56358519942349390412016-01-13T04:22:00.000-08:002016-01-13T04:22:43.022-08:00PowerShell: List all IPv4 Addresses<span style="font-family: Arial, Helvetica, sans-serif;">A very short blog post today. I'm not sure why this is so complicated, maybe there's an easier way, or a more recent cmdlet that allows it to be obtained in an easier way. </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">I want to list all IP (v4) addresses and nothing else with a single line PowerShell command that is backwards compatible with all versions of PowerShell.</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Here's what I came up with:</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-size: x-small;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;">foreach</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> ( </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$i</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;">in</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> (</span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">Win32_NetworkAdapterConfiguration</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root\CIMV2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">where</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">IPEnabled </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-eq</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"True"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> } </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">select</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IPAddress</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">) ) { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$i</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">IPAddress</span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">[</span></span></span><span style="color: purple; font-family: Lucida Console;"><span style="color: purple; font-family: Lucida Console;"><span style="color: purple; font-family: Lucida Console;">0</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">]</span></span></span></span><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;"> }</span> </span></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Here's a quick breakdown of the command</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">It's basic structure uses a foreach loop</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"> <span style="font-size: x-small;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;">Foreach</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> ( </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$TempVariable</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;">in</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$MyVariableList</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> ) { </span></span><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;">do</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">this</span></span></span></span><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;"> }</span> </span></span></span><span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"><span style="color: blue;">$i</span> is my temporary variable, that exists only for the purposes of the loop. The Foreach loop will cycle through each object in the second variable, and each time it will be represented by <span style="color: blue;">$i</span></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"><span style="color: blue;">$MyVariableList</span> is a variable that contains many objects, and is often obtained in a script by a separate command. As I want a one-liner, I have substituted this variable with a command that produces a list of objects. </span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">This is my command: </span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"><span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">Win32_NetworkAdapterConfiguration</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root\CIMV2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">where</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">IPEnabled </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-eq</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"True"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> } </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">select</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IPAddress</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">)</span></span></span></span><br />
<span style="font-family: Lucida Console; font-size: xx-small;"></span><br />
<span style="font-family: Arial;">It uses <span style="color: blue;">Get-WMIObject</span> to return the WMI class <span style="color: blue;">Win32_NetworkAdapterConfiguration</span>. I chose the <span style="color: blue;">Get-WMIObject</span> command to return the IP address data because I know it is compatible with all version of PowerShell. This command on its own returns a large amount of data, so I have piped the results to the <span style="color: blue;">Where-Object</span> command. This filters to return only network adapters that are enabled. These results are then piped to the <span style="color: blue;">Select-Object</span> command, and this selects the single property of IP address. </span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKZ9vgQciBiKpFoVj8ki3w_OPbf6mM21uKMZY5snmuBPvqqMqxHkunKRtL7CArPo8uJHu2ccnmPm89dFZOgpKXd5yB4uo1DqEpNQhiw9uTdLV3MDQhWDIQqDBN_vXJGkGv_Xo7Ue3rT5k/s1600/IPv4.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="51" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKZ9vgQciBiKpFoVj8ki3w_OPbf6mM21uKMZY5snmuBPvqqMqxHkunKRtL7CArPo8uJHu2ccnmPm89dFZOgpKXd5yB4uo1DqEpNQhiw9uTdLV3MDQhWDIQqDBN_vXJGkGv_Xo7Ue3rT5k/s320/IPv4.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">IP Address properties</td></tr>
</tbody></table>
<br />
<br />
<br />
<br />
<br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">The result is an IP address object for each adapter. Each contains both an IPv4 and IPv6 </span><span style="font-family: Arial, Helvetica, sans-serif;">address.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">{ do this }</span> Finally the Foreach loop will carry out an action on each object that is returned. In this case it simply takes the object and calls the IPAddress property (which is the only one available). The square brackets specify the 1st result only will be displayed.</span><br />
<span style="font-family: Arial;"></span><br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF9ypw0gkytjFxh9Osgilt6C3JanmvnMy7MGNyuuriZjFvIHSoABata8zRQ_ppLnUa6yqv6Hx6rrXWmocIihj_WQfNGz8Ic7AtkPxvjKiv3oDiHxYGm9DFTAgWHFKCHRu3_3tHKuGwZVE/s1600/IPv4-1.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="28" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF9ypw0gkytjFxh9Osgilt6C3JanmvnMy7MGNyuuriZjFvIHSoABata8zRQ_ppLnUa6yqv6Hx6rrXWmocIihj_WQfNGz8Ic7AtkPxvjKiv3oDiHxYGm9DFTAgWHFKCHRu3_3tHKuGwZVE/s320/IPv4-1.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">IP Address list</td></tr>
</tbody></table>
<br />
<br />
<br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Simple.</span><br />
<br />
<br />
<br />
<br />
Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com0tag:blogger.com,1999:blog-394719478213759008.post-73162541927154404192016-01-06T13:30:00.000-08:002016-01-06T13:30:34.773-08:00Scripting IIS App Pools (v8.5) with PowerShell<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"><strong>App Pools</strong></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">It's quite common to automate the process for creating a web site and its associated application pools. Creating an app pool is a simple process, but the many different settings that can be used is where things can get complicated. In my experience I found that PowerShell's <strong>Set-ItemProperty</strong> can get complicated when it's used with IIS app pools, so here's a few things I found out.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial;">The IIS:\ provider doesn't work unless the WebAdministration module is first imported. So the following command must be run at the beginning of any script</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Import-Module WebAdministration or ipmo webadministration</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">To fetch a list of app pools, run</span><br />
<span style="font-family: Arial;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"></span></span></span><br />
<span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-Item</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: small;">IIS:\AppPools\*</span> </span></span></span></span><span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Whenever I'm working with something for the first time, I select one object, then pass it to the <span style="color: blue;">Format-List</span> cmdlet which enables me to see every available property.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"></span></span></span><br />
<span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-Item</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIS:\AppPools\*</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">select-object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-First</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: purple; font-family: Lucida Console;"><span style="color: purple; font-family: Lucida Console;"><span style="color: purple; font-family: Lucida Console;">1</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Format-List</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Property</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">*</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">This displays all the properties that were hidden from the results of the first <span style="background-color: white; color: blue;">Get-Item</span> command. I could also select a specific app pool</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"> <span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-Item</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIS:\AppPools\MyAppPool</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Format-List</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Property</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">*</span></span></span><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;"> </span> </span></span></span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">I can see several results display <strong>Microsoft.IIs.PowerShell.Framework.ConfigurationElement</strong> rather than an actual <span style="background-color: white;">value</span>. </span><br />
<span style="font-family: Arial;"></span><br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTi69qfcO-9xJijzo7PZxL2uQqgjAYUdPWjrmB2559wrxEtXeKoyQQQBqY51Vu-vn5pM4eSTitukotKqxM0dW3KFnmxuCc4voYOjHjb-Szvc_x6AK6hB5jvHSgrOvqMgS5KOwDbzkAMd4/s1600/AppPools02.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="34" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTi69qfcO-9xJijzo7PZxL2uQqgjAYUdPWjrmB2559wrxEtXeKoyQQQBqY51Vu-vn5pM4eSTitukotKqxM0dW3KFnmxuCc4voYOjHjb-Szvc_x6AK6hB5jvHSgrOvqMgS5KOwDbzkAMd4/s320/AppPools02.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif; font-size: xx-small;">App Pool properties</span></td></tr>
</tbody></table>
<br />
<span style="font-family: Arial;"></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"></span></span></span></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"></span></span></span></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"></span></span></span></span><br />
<span style="color: black; font-family: Arial, Helvetica, sans-serif;">This is where we need to switch to the <span style="color: blue;">Get-ItemProperty</span> cmdlet to see the property details in full.</span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"></span></span></span></span><br />
<span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-Item</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIS:\AppPools\*</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">select-object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-First</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: purple; font-family: Lucida Console;"><span style="color: purple; font-family: Lucida Console;"><span style="color: purple; font-family: Lucida Console;">1</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-ItemProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: small;">processmodel</span> </span></span></span><br />
<br />
<span style="font-family: Arial;">or for a specific App Pool</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-Item</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIS:\AppPools\MyAppPool</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-ItemProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: small;">processmodel</span> </span></span></span></span><span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">this can also be written as </span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> <span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">(</span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-ItemProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIS:\AppPools\MyAppPool</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">)</span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-size: small;">processmodel</span> </span></span></span><span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">or </span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"> <span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-ItemProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIS:\AppPools\MyAppPool</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: small;">processmodel</span> </span></span></span></span><span style="font-family: Arial;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">The results show that <strong>processmodel</strong> has several properties.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8zYFYfOqOSlBHLPrX-PiuaCcSsvN5vkzwkNbTWqHhglr7zXFzMbd9Jk0-HJI_LRucBZTduoQLD5PuLWnp2Ap5Q5a7PUky3x7ZNaKRscfOp2Nj-DFaElrpqJN-73wV9thK0Xe-MeMJ8Mc/s1600/AppPools01.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="120" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8zYFYfOqOSlBHLPrX-PiuaCcSsvN5vkzwkNbTWqHhglr7zXFzMbd9Jk0-HJI_LRucBZTduoQLD5PuLWnp2Ap5Q5a7PUky3x7ZNaKRscfOp2Nj-DFaElrpqJN-73wV9thK0Xe-MeMJ8Mc/s320/AppPools01.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif;">processModel properties</span></td></tr>
</tbody></table>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">I expected to be able to change one of these properties by running a command like this</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Set-ItemProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIS:\AppPools\MyAppPool</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">processmodel.identitytype</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Value</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: small;">ApplicationPoolIdentity</span> </span></span></span></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">When I run this command, it executes without an error, but no changes are made.</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Similarly with other App Pool settings the <span style="color: blue;">Set-ItemProperty</span> command does not make changes.</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Set-ItemProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIS:\AppPools\MyAppPool</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">managedPipeLineMode</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-value</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: small;">Integrated</span> </span></span></span></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">After some experimentation I found that the name parameter of Set-ItemProperty is case sensitive</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">When I go back and examine my previous commands, I can see that processmodel is in fact <strong>processModel</strong>, and identitytype is <strong>identityType</strong>. Also I should've been using <strong>managedPiplineMode</strong>.</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Once I change my commands accordingly, the Set-ItemProperty command correctly makes the changes.</span><br />
<br />
<span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Set-ItemProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIS:\AppPools\MyAppPool</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">processModel.identityType</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Value</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">ApplicationPoolIdentity</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><br />
<span style="font-size: x-small;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: x-small;"> </span><span style="font-size: small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Set-ItemProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIS:\AppPools\MyAppPool</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">managedPipelineMode</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-value</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: small;">Integrated</span> </span></span></span></span><span style="font-family: Arial;"></span><br />
<br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com1tag:blogger.com,1999:blog-394719478213759008.post-71661685100052643902015-11-12T08:34:00.000-08:002016-02-02T02:09:51.848-08:00** Fixed ** Error: 0x800f081f 0x800f0907. The source files could not be found. Installing .Net Framework v3.5 on Windows Server 2012<span style="font-family: "arial" , "helvetica" , sans-serif;"><strong>Scroll down to the <em>update</em> for the fix</strong>, continue reading below for some background.</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Today I thought I would write about the process of installing .Net Framework v3.5 on Windows Server 2012 when the server does not have an internet connection. This process caused me a lot of problems and I wasted a lot of time on it today. It seems many others are experiencing the same problem.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Windows Server 2012 requires that .Net Framework is enabled via as a feature rather than using the installation file method that we are used to in previous versions of Windows. For servers with an internet connection this works fine, and can be achieved in a number of ways (eg. Add roles and features wizard, PowerShell). My problems began when I started working on a server without internet access.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">The official guide from Microsoft is </span><a href="https://technet.microsoft.com/en-GB/library/dn482071.aspx" target="_blank"><span style="font-family: "arial" , "helvetica" , sans-serif;">here</span></a><span style="font-family: "arial" , "helvetica" , sans-serif;">, and it all sounds simple enough. Doing this with the wizard displayed a warning before I started.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikkVRbbR38W7FsszQ6QdCRAhyobxnfQDpk_qRTu3d-wO8kofaIIoqyUiQ5wAY0ZT0r9T0SwmQlJ4PKf5LFDNmVZOrXdTbZM1JfQQpoked0yb4c7mdQ_yVeoUIbrznyQbzrNBB4ZHOIlrE/s1600/001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><img border="0" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikkVRbbR38W7FsszQ6QdCRAhyobxnfQDpk_qRTu3d-wO8kofaIIoqyUiQ5wAY0ZT0r9T0SwmQlJ4PKf5LFDNmVZOrXdTbZM1JfQQpoked0yb4c7mdQ_yVeoUIbrznyQbzrNBB4ZHOIlrE/s320/001.jpg" width="320" /></span></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif;"></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Selecting the Install option (as expected) caused the installation to fail:</span><br />
<span style="font-family: "arial";">"Installation of one or more roles, role services, or features failed.</span><br />
<span style="font-family: "arial";">The source files could not be found. Try installing the roles, role services, or features again in a new Add Roles and Features Wizard session, and on the Confirmation page of the wizard, click "Specify an alternate source path" to specify a valid location of the source files that are required for the installation. The location must be accessible by the computer account of the destination server"</span><br />
<span style="font-family: "arial";"></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPCZenYU3t7IEym7M1BKRVowiH3FX3xU-xN5sb6NHCjuTOpcfenkKhVNT97f1iv9duJ9LRbj3m45ApnfCpHgZOkI_XtkUP6VZSRP116FoOQ0AKdfvLTfZLGcxb9FwSX3poetuEG2MvKYw/s1600/002.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPCZenYU3t7IEym7M1BKRVowiH3FX3xU-xN5sb6NHCjuTOpcfenkKhVNT97f1iv9duJ9LRbj3m45ApnfCpHgZOkI_XtkUP6VZSRP116FoOQ0AKdfvLTfZLGcxb9FwSX3poetuEG2MvKYw/s320/002.jpg" width="320" /></a></div>
<br />
<br />
<span style="font-family: "arial";">I followed the advice in the error, and copied the .\sources\sxs folder from the installation DVD to a local folder, then selected that folder within the "Specify an alternate source path" option of the wizard.</span><br />
<span style="font-family: "arial";">This did not make any difference and the installation failed with the same error.</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">A few google searches led me to this <a href="https://support.microsoft.com/en-us/kb/3005628" target="_blank">article</a>, which references KB3005628 as a fix for this problem. However, this fix corrects the problem when it was caused by the installation of security update 2966827 or 2966828. </span><br />
<br />
<span style="font-size: x-small;"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">Get-Hotfix</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">|</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">where</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> { (</span></span><span style="color: orangered; font-family: "lucida console";"><span style="color: orangered; font-family: "lucida console";"><span style="color: orangered; font-family: "lucida console";">$_</span></span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">.</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";">HotfixID </span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">-eq</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: darkred; font-family: "lucida console";"><span style="color: darkred; font-family: "lucida console";"><span style="color: darkred; font-family: "lucida console";">"KB296682"</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">-or</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: orangered; font-family: "lucida console";"><span style="color: orangered; font-family: "lucida console";"><span style="color: orangered; font-family: "lucida console";">$_</span></span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">.</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";">HotfixID </span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">-eq</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: darkred; font-family: "lucida console";"><span style="color: darkred; font-family: "lucida console";"><span style="color: darkred; font-family: "lucida console";">"KB2966828"</span></span></span></span><span style="font-family: "lucida console"; font-size: xx-small;"><span style="font-family: "lucida console"; font-size: xx-small;"><span style="font-size: x-small;">) }</span> </span></span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">This PowerShell command will reveal whether or not these updates have been installed. In my case the server was not patched and so this was not the cause of the problem.</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">Various further google searches revealed many other users have similar issues, and I tried several other methods of installing .Net Framework v3.5, and all of them failed. Here are a few examples:</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Dism /online /enable-feature /featurename:NetFX3 /all /Source:d:\sources\sxs</span><br />
<span style="font-family: "arial";"></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX3EWki_0ohVomDWMZ-DjhAgFeFX6QRTeX7aqMKo_rEt0Py8o_MfRPjf4bUjW6uS94vhO3Lbra8zqm2471Kwejv_Mw4jI-wybhntL1hcGKTzIf074ajzOhvLSViLufzg-adHI1RZ8aoHw/s1600/003.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="126" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX3EWki_0ohVomDWMZ-DjhAgFeFX6QRTeX7aqMKo_rEt0Py8o_MfRPjf4bUjW6uS94vhO3Lbra8zqm2471Kwejv_Mw4jI-wybhntL1hcGKTzIf074ajzOhvLSViLufzg-adHI1RZ8aoHw/s320/003.jpg" width="320" /></a></div>
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Dism /Online /Enable-Feature /FeatureName:NetFx3 /Source:X:\Sources\WinSXS /all /limitaccess</span><br />
<span style="font-family: "arial";"></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv4EoLvov0sAq5h4OtBKue2Z0JZdXH3rP51Lv_EBy9zynT86ePZEl4t0TwCkKFdndHLgUFtF54h3Yu3SPabawHgoDOTyXN_yOdOFZFv77MkCD6ypkpWwmRrTnTLtmTnKc45g0E4d-ZoLE/s1600/Netfx35001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="163" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv4EoLvov0sAq5h4OtBKue2Z0JZdXH3rP51Lv_EBy9zynT86ePZEl4t0TwCkKFdndHLgUFtF54h3Yu3SPabawHgoDOTyXN_yOdOFZFv77MkCD6ypkpWwmRrTnTLtmTnKc45g0E4d-ZoLE/s320/Netfx35001.jpg" width="320" /></a></div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Install-WindowsFeature –Name NET-Framework-Features –Source D</span><span style="font-family: "arial" , "helvetica" , sans-serif;">:\Sources\sxs</span><br />
<span style="font-family: "arial";"></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH0KWCeGsK2XZ-QOtnRsnO3-oaHl0_H1CwjsYx_2jOerwKW9sOgEhvpIrcx3-l6EoB0ssSTOjaVowBiYOilS5clv_VOrDXS1LOOV6wOCXHbkadxgRK0g9Tbou6UKD7AHkZdRpYt9JUEJI/s1600/004.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="78" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH0KWCeGsK2XZ-QOtnRsnO3-oaHl0_H1CwjsYx_2jOerwKW9sOgEhvpIrcx3-l6EoB0ssSTOjaVowBiYOilS5clv_VOrDXS1LOOV6wOCXHbkadxgRK0g9Tbou6UKD7AHkZdRpYt9JUEJI/s320/004.jpg" width="320" /></a></div>
<span style="font-family: "arial";"></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">I also tried to enable the policy <strong>Specify settings for optional component installation and component repair.</strong></span><br />
<span style="font-family: "arial";">This is located in Computer Configuration\Administrative Templates\System</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">I enabled the policy and enabled "Never attempt to download payload from Windows Update". This made no difference, and the installation still fails no matter how I attempt to install it.</span><br />
<h3>
</h3>
<h3>
<span style="font-family: "arial" , "helvetica" , sans-serif;">** Update **</span></h3>
<h3>
<span style="font-family: "arial" , "helvetica" , sans-serif;">01 Feb 2016</span></h3>
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">Today I finally resolved this problem, below are the steps I had to take to get it working, hopefully this method can save someone some time. Note that this fix requires a Windows Server 2012 r2 machine on which the .Net 3.5 installation has been successful</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">First, follow the steps in this <a href="https://support.microsoft.com/en-us/kb/2734782" target="_blank">Microsoft support page</a>. If these steps don't help, as was the case for me, try using my method.</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";"><strong>Step 1</strong></span><br />
<span style="font-family: "arial";">On a server where the installation fails, get a list of all folders in the WinSXS folder.</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">I used the following PowerShell command</span><br />
<span style="font-family: "arial";"></span> <span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">Get-ChildItem</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";">-Path</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";">C:\Windows\WinSxS</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">|</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">select</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";">name</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">|</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">out-file</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blueviolet; font-family: "lucida console"; font-size: xx-small;"><span style="color: blueviolet; font-family: "lucida console"; font-size: xx-small;"><span style="color: blueviolet; font-family: "lucida console"; font-size: xx-small;"><span style="font-size: small;">D:\WinSXSfiles.txt</span> </span></span></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Then I copied WinSXSfiles.txt to a server where a previous installation had been successful.</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";"><strong>Step2</strong></span><br />
<span style="font-family: "arial";">Copy the list of folders to a (Windows 2012 r2) server where the installation has been successful. Compare this list to the contents of the WinSXS folder (on the successful server), and get a copy of all the folders that are missing on the server where the install fails.</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">I used the following PowerShell script:</span><br />
<span style="font-family: "arial";"></span><br />
<span style="color: darkgreen; font-family: "lucida console";"><span style="color: darkgreen; font-family: "lucida console";"><span style="color: darkgreen; font-family: "lucida console";">#Get the folder contents of local WinSXS, select only the name, pass to foreach command</span></span></span><br />
<span style="color: darkgreen; font-family: "lucida console";"><span style="color: darkgreen; font-family: "lucida console";"><span style="color: darkgreen; font-family: "lucida console";">
</span></span></span><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">Get-ChildItem</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";">C:\Windows\WinSxS</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">|</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">select</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";">-ExpandProperty</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";">name</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">|</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">foreach</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> {</span></span><br />
<span style="font-family: "lucida console";"><span style="font-family: "lucida console";">
</span></span><br />
<span style="color: darkgreen; font-family: "lucida console";"><span style="color: darkgreen; font-family: "lucida console";"><span style="color: darkgreen; font-family: "lucida console";">#Foreach folder name, check whether it exists in the list of folders from the problem machine</span></span></span><br />
<span style="color: darkblue; font-family: "lucida console";"><span style="color: darkblue; font-family: "lucida console";"><span style="color: darkblue; font-family: "lucida console";">if</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> ( </span></span><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";"><span style="color: darkgrey; font-family: "lucida console";">!</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";">(</span></span><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">select-string</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";">-Path</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";">D:\WinSXSfiles.txt</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";">-Pattern</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: orangered; font-family: "lucida console";"><span style="color: orangered; font-family: "lucida console";"><span style="color: orangered; font-family: "lucida console";">$_</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";">) ) {</span></span><br />
<span style="font-family: "lucida console";"><span style="font-family: "lucida console";">
</span></span><br />
<span style="color: darkgreen; font-family: "lucida console";"><span style="color: darkgreen; font-family: "lucida console";"><span style="color: darkgreen; font-family: "lucida console";">#Write any missing folder names to the console</span></span></span><br />
<span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">Write-Host</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: orangered; font-family: "lucida console";"><span style="color: orangered; font-family: "lucida console";"><span style="color: orangered; font-family: "lucida console";">$_</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";">-ForegroundColor</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";">Yellow</span></span></span><br />
<span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";">
</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";">
</span></span><br />
<span style="color: darkgreen; font-family: "lucida console";"><span style="color: darkgreen; font-family: "lucida console";"><span style="color: darkgreen; font-family: "lucida console";">#Copy missing folders to a temporary folder D:\WinSXS</span></span></span><br />
<span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";"><span style="color: blue; font-family: "lucida console";">Copy-Item</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: darkred; font-family: "lucida console";"><span style="color: darkred; font-family: "lucida console";"><span style="color: darkred; font-family: "lucida console";">"C:\Windows\WinSxS\</span></span></span><span style="color: orangered; font-family: "lucida console";"><span style="color: orangered; font-family: "lucida console";"><span style="color: orangered; font-family: "lucida console";">$_</span></span></span><span style="color: darkred; font-family: "lucida console";"><span style="color: darkred; font-family: "lucida console";"><span style="color: darkred; font-family: "lucida console";">"</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";">-Destination</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";"><span style="color: blueviolet; font-family: "lucida console";">D:\WinSXS\</span></span></span><span style="font-family: "lucida console";"><span style="font-family: "lucida console";"> </span></span><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";">-Recurse</span></span></span><br />
<span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";"><span style="color: navy; font-family: "lucida console";">
</span></span></span><span style="font-family: "lucida console"; font-size: xx-small;"><span style="font-family: "lucida console"; font-size: xx-small;"><span style="font-size: small;">}</span><br />
<span style="font-size: small;">
</span><span style="font-size: small;">}</span></span></span><br />
<span style="font-family: "lucida console"; font-size: xx-small;"><span style="font-family: "lucida console"; font-size: xx-small;"> </span></span><br />
<span style="font-family: "arial";"><strong>Step 3</strong></span><br />
<span style="font-family: "arial";">Copy the missing folders to the server where the installation fails</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";"><strong>Step 4</strong></span><br />
<span style="font-family: "arial";">Use Dism, with the Source option pointing at both WinSXS folders.</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">Dism /Online /Enable-Feature /FeatureName:NetFx3 /Source:C:\Windows\WinSXS /Source:D:\WinSXS /all /limitaccess</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">In my example I use 2 WinSXS folders. I didn't want to copy nearly 700 potentially unnecessary folders into the WinSXS folder on the C: drive. To get around this I created a temporary WinSXS folder (<strong>D:\WinSXS</strong>) and gave the DISM command a second <strong>/Source </strong>folder. </span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">I found <a href="https://technet.microsoft.com/en-GB/library/hh824822.aspx" target="_blank">this page</a> useful for explaining the DISM switches.</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">I had nearly 700 extra folders in WinSXS on my machine where the installation was successful. Looking through these I found a large number with names that started amd64_netfx</span><br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";">I expect that with some trial and error I could work out the exact folders that were necessary for the installation to be successful - probably some/all of those with names starting amd64_netfx.</span><br />
<span style="font-family: "arial";">However, to save time, my method of creating a temporary WinSXS folder works fine.</span><br />
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
<br />
<span style="font-family: "arial";"></span><br />
<span style="font-family: "arial";"></span><br />Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com27tag:blogger.com,1999:blog-394719478213759008.post-67699721044344416982015-08-19T05:41:00.000-07:002015-10-19T12:01:22.437-07:00Import PowerShell Module from a UNC path share<span style="font-family: Arial, Helvetica, sans-serif;">Recently I have put all my most commonly used PowerShell scripts into a Module. By bundling them together into a module, I remove the need for individual script files to be maintained and updated on all servers in the network.</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Doing this has caused a few problems of its own, so here is the process I used to get it working. </span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">The first thing I did was copy the module to a shared location that can be accessed easily by everything on the network.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Next, anything that needs to use my module needs to be made aware of it. There are 2 steps to this process.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br />1. Edit the environment variable “<strong>PSModulePath</strong>” to include the path to the module <br />2. Import the module</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Both steps can be accomplished by editing the PowerShell profile. There are several PowerShell profiles; I have chosen to use the profile for <strong>All Users, All Hosts</strong>. This ensures the module will be available no matter how PowerShell is used. This is important for me because as well as running commands locally I also call commands using external applications like Nagios.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">More information on PowerShell profiles can be found </span><a class="wiki external" href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/21/understanding-the-six-powershell-profiles.aspx" rel="external nofollow" target="_blank"><span style="font-family: Arial, Helvetica, sans-serif;">here</span></a><span class="icon icon-link-external fa fa-external-link fa-fw "></span><span style="font-family: Arial, Helvetica, sans-serif;">: </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">The <strong>All Users, All Hosts</strong> profile is located here: <br /><span style="color: blue;">C:\windows\system32\WindowsPowerShell\v1.0\profile.ps1</span> </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">The <strong>profile.ps1</strong> file will not exist by default, so it is usually necessary to create it (new text file called profile.ps1) </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /><span style="background-color: #eeeeee;">1. Edit the environment variable “<strong>PSModulePath</strong>” to include the path to the module </span>This done by adding the following line to the PowerShell profile:</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"> <span style="font-size: x-small;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$env:psmodulepath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">=</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$env:psmodulepath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">+</span></span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">";\\ServerShare\Folder\modules"</span></span></span></span></span><br />
<br />
<span style="background-color: #eeeeee; font-family: Arial;">2. Import the module</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">This done by adding the following line to the PowerShell profile: </span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"> <span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Import-Module</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">ModuleName</span> </span></span></span></span><span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Launching PowerShell will give you an error message at this point. This is because PowerShell sees the module as coming from an external source and doesn't trust it. PowerShell uses Internet Explorer's Zone Policy to see if it trusts the file, script or module you are attempting to run.</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">This can be manually edited through: </span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Internet Options >> Security tab >> Local Intranet >> Sites </span><br />
<span style="font-family: Arial;">Here we can add the external source as a trusted site, <a href="file://servershare/">\\ServerShare</a></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Doing this will only take effect for the currently logged on user, and will still cause an error when an external program attempts to run something using PowerShell - eg. Nagios</span><br />
<br />
<span style="font-family: Arial;">To get around this we must add the trusted site to the local machine's trusted zone policy. This can be done by creating two new registry keys. </span><br />
<br />
<span style="font-family: Arial; font-size: x-small;"><strong>HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\ServerShare</strong></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Name: file</span><br />
<span style="font-family: Arial;">Type: DWORD</span><br />
<span style="font-family: Arial;">Value: 1</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">and </span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><strong>HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\ServerShare</strong></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Name: file</span><br />
<span style="font-family: Arial;">Type: DWORD</span><br />
<span style="font-family: Arial;">Value: 1</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial;">I have a lot of servers that require this change, so I wrote some PowerShell that will do it for me, here is the script:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial;"><span style="font-size: x-small;"> <span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$registryPath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">=</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\ServerShare"</span></span></span></span><br />
<span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console; font-size: x-small;">
</span></span></span><span style="font-size: x-small;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$registryPath1</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">=</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\ServerShare"</span></span></span></span><br />
<span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console; font-size: x-small;">
</span></span></span><span style="font-size: x-small;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">=</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"file"</span></span></span></span><br />
<span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console; font-size: x-small;">
</span></span></span><span style="font-size: x-small;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$value</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">=</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"1"</span></span></span></span><br />
<span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console; font-size: x-small;">
</span></span></span><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"></span></span></span><br />
<span style="font-size: x-small;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;">If</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> (</span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">!</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">(</span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">test-path</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$registryPath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> )) {</span></span></span><br />
<span style="font-family: Lucida Console;"><span style="font-family: Lucida Console; font-size: x-small;">
</span></span><span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">New-Item</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Path</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$registryPath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Force</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Out-Null</span></span></span></span><br />
<span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console; font-size: x-small;">
</span></span></span><span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">New-ItemProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Path</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$registryPath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Value</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$value</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-PropertyType</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">DWORD</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Force</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Out-Null</span></span></span></span><br />
<span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"><span style="font-size: x-small;">}</span><br />
<span style="font-size: x-small;">
</span></span></span><span style="font-size: x-small;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;">If</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> (</span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">!</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">(</span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">test-path</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$registryPath1</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> )) {</span></span></span><br />
<span style="font-family: Lucida Console;"><span style="font-family: Lucida Console; font-size: x-small;">
</span></span><span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">New-Item</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Path</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$registryPath1</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Force</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Out-Null</span></span></span></span><br />
<span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console; font-size: x-small;">
</span></span></span><span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">New-ItemProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Path</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$registryPath1</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Value</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$value</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-PropertyType</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">DWORD</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Force</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Out-Null</span></span></span></span><br />
<span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">}</span> </span></span></span><br />
<span style="font-family: Arial;">Using these settings let me use all the commands that are exposed by my module and I can leave the execution policy set at Remote Signed.</span><br />
<br />
<span style="font-family: Arial;">Below are some good articles that helped me out with this process:</span><br />
<span style="font-family: Arial;"></span><br />
<a href="http://setspn.blogspot.de/2011/05/running-powershell-scripts-from-unc.html" target="_blank"><span style="color: blue;">Running PowerShell Scripts From An UNC Path (Share)</span></a><br />
<a href="http://www.hanselman.com/blog/SigningPowerShellScripts.aspx" target="_blank"><span style="color: blue;">Signing PowerShell Scripts</span></a><br />
<a href="http://community.spiceworks.com/topic/1040473-can-t-import-a-module-from-a-unc-path" target="_blank"><span style="color: blue;">Can't import a module from a UNC path</span></a><br />
<a href="http://blogs.technet.com/b/heyscriptingguy/archive/2015/04/02/update-or-add-registry-key-value-with-powershell.aspx" target="_blank"><span style="color: blue;">Update or Add Registry Key Value with PowerShell</span></a><br />
<br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">UPDATE - 19-10-2015</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">I've been using this process quite a bit, and found that it doesn't work in all circumstances. For newer versions of Internet Explorer, there is an extra step to editing the Local Intranet zones policy:</span><br />
<span style="font-family: Arial;">Internet Options >> Security tab >> Local Intranet >> Sites >> Advanced</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">When using these later versions of IE, the registry changes don't work, and the module on a UNC path still causes an error when the profile tries to import it. I can stop the error from being displayed by changing the Execution Policy to Bypass, however, I wasn't keen on implementing that as a solution across our estate. Instead I'm now using a different method.</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"> <span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Copy-Item</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">\\ServerShare\Folder\modules\ModuleName</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Destination</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">D:\scripts\modules</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Recurse</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Force</span></span></span></span><br />
<span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console; font-size: x-small;">
</span></span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"></span></span></span><br />
<span style="font-size: x-small;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$env:psmodulepath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">=</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$env:psmodulepath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">+</span></span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">";D:\scripts\modules"</span></span></span></span><br />
<span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console; font-size: x-small;">
</span></span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"></span></span></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Import-module</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">ModuleName </span></span></span></span></span><br />
<br />
<span style="font-family: Arial;">This takes a copy of the module and puts it into a local folder. The module is then imported from this local folder, which removes the need for PowerShell to treat it as a remote script.</span><br />
<span style="font-family: Arial;"><br />
</span><span style="font-family: Arial;"><br /></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com1tag:blogger.com,1999:blog-394719478213759008.post-64814493085431098432015-01-14T05:36:00.000-08:002015-01-14T06:08:07.022-08:00Use PowerShell to search Windows Event Logs<span style="font-family: Arial, Helvetica, sans-serif;">PowerShell is an excellent tool for searching through Windows event logs. I find myself using it more and more these days as it enables me to find the information I need much quicker than using the filter feature of the Event Viewer snap in.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">The cmdlet to use for searching the event logs is get-eventlog. For the full help file from PowerShell, enter the following</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">help</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">Get-EventLog</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: navy; font-family: Lucida Console; font-size: xx-small;"><span style="color: navy; font-family: Lucida Console; font-size: xx-small;"><span style="color: navy; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">-Full</span> </span></span></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">The get-eventlog cmdlet uses the switch -LogName. This is used to specify the event log you want to search, eg System, Application etc.</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">To get a list of available event logs, enter</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-size: x-small;"> <span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-EventLog</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-List</span></span></span></span><br />
<span style="color: navy; font-family: Lucida Console; font-size: xx-small;"><span style="color: navy; font-family: Lucida Console; font-size: xx-small;"><span style="color: navy; font-family: Lucida Console; font-size: xx-small;">
</span></span></span><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"></span></span></span><br />
<span style="font-family: Arial;">or</span><br />
<span style="color: blue; font-family: Lucida Console; font-size: xx-small;"><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"></span></span></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-EventLog</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-LogName</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">*</span> </span></span></span><br />
<span style="font-family: Arial;"></span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDQRp56rwbtDNApgIsu6Bro1J1W4-ZxeFdzL2He1jqJex__jJnfxeHyPt3Na7gLhOsz-J92ctgQ3qx1D4bnjbmugcMQXlI65yqpKw9NFFjCLEmlhgO_sUqVRr1Y_dxglrc99hd2R7GCD8/s1600/EventLog1.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDQRp56rwbtDNApgIsu6Bro1J1W4-ZxeFdzL2He1jqJex__jJnfxeHyPt3Na7gLhOsz-J92ctgQ3qx1D4bnjbmugcMQXlI65yqpKw9NFFjCLEmlhgO_sUqVRr1Y_dxglrc99hd2R7GCD8/s1600/EventLog1.jpg" height="120" width="320" /></a></div>
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">You can then list all events from that event log with the command Get-EventLog -LogName LogName</span><br />
<span style="font-family: Arial;">Eg,</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-EventLog</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-LogName</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">System </span></span></span></span><br />
<span style="font-family: Arial;"><br />
This will return everything from the event log, probably hundreds or even thousands of events, so the next job is to filter for the events you are interested in.<br />
<br />
We can examine an individual event log to get an idea of how to filter <br />
<br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-EventLog</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-LogName</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">System</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Newest</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: purple; font-family: Lucida Console; font-size: xx-small;"><span style="color: purple; font-family: Lucida Console; font-size: xx-small;"><span style="color: purple; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">1</span> </span></span></span><br />
<br />
This command will return the most recent System event log<br />
</span><br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWknR6yZn16wPNXePe59Krz_LlNm4NjMiWtV7DNfZst1iHEcgurEgV7SE-a2klwRBPnS331UI6N0gORy9LuJADtwVDlkV8cZixjU_ahNlH_5YEy8qArRR_vlo7fDzGa4LGiKFThbB6nCM/s1600/EventLog2.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWknR6yZn16wPNXePe59Krz_LlNm4NjMiWtV7DNfZst1iHEcgurEgV7SE-a2klwRBPnS331UI6N0gORy9LuJADtwVDlkV8cZixjU_ahNlH_5YEy8qArRR_vlo7fDzGa4LGiKFThbB6nCM/s1600/EventLog2.jpg" height="40" width="320" /></a></div>
<br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">The information displayed is a subset of the complete data available for this event log. PowerShell will automatically select the columns to display so that it fits easily on the screen. To see everything, we need to pipe the output to the format-list cmdlet.</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"> <span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-EventLog</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-LogName</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">System</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Newest</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: purple; font-family: Lucida Console;"><span style="color: purple; font-family: Lucida Console;"><span style="color: purple; font-family: Lucida Console;">1</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Format-List</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Property</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">*</span> </span></span></span></span><span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">This command returns all the properties and values for this event log</span><br />
<span style="font-family: Arial;"></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5IRpSu8BNmAwDSETw3mk7WsvY6cAuZkFGcU4ICdYIzCn4-5ZMv4ApL5ENTu2SbvlVr5CevoYnhBDpErvXlgDsZzI94VLadmoWaJx4P1ffXxBQHKhwt4i9eS1xFU6JpxXvOgQQz7ueJ5Y/s1600/EventLog3.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5IRpSu8BNmAwDSETw3mk7WsvY6cAuZkFGcU4ICdYIzCn4-5ZMv4ApL5ENTu2SbvlVr5CevoYnhBDpErvXlgDsZzI94VLadmoWaJx4P1ffXxBQHKhwt4i9eS1xFU6JpxXvOgQQz7ueJ5Y/s1600/EventLog3.jpg" height="147" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Now you can see all the familiar properties of the event, such as EventID, EntryType, Time Written etc. I can now filter my result based on one or more of these properties. </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">For example, </span><br />
<span style="font-family: Arial;">show all events where the message contains "the service entered the stopped state"</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">show all events where the event id equals 41 and the date is 10 Jan 2015</span><br />
<span style="font-family: Arial;">show all events where the EntryType is error, the source is Asp.Net or .Net runtime and the date is between 01 Jan - 10 Jan 2015</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">All of this is achieved by piping the results of get-eventlog to the where-object cmdlet</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-EventLog</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-LogName</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">System</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Where-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">Message </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-like</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"*the service entered the stopped state*"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> } </span></span></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">In this example you can see that I have used the Message property of the event and the -like operator to match it to the text I am looking for.</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"> <span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-EventLog</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-LogName</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">System</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Where-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">EventID </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-eq</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: purple; font-family: Lucida Console;"><span style="color: purple; font-family: Lucida Console;"><span style="color: purple; font-family: Lucida Console;">41</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-and</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">TimeWritten </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-like</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"01/14/2015*"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> } </span></span></span></span><br />
<span style="font-family: Arial;">In this example you can see that I have used the EventID and TimeWritten properties of the event</span><br />
<span style="font-family: Arial;">$_.EventID -eq 41</span><br />
<span style="font-family: Arial;">$_.TimeWritten -like "01/14/2015*"</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">The -and operator links these two properties together</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-EventLog</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-LogName</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">System</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-After</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> (</span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-Date</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Date</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">'1/1/2015'</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">) </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Before</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> (</span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-Date</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Date</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">'10/1/2015'</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">) </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Where-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">EntryType </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-eq</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"Error"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-and</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> (</span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">Source </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-like</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"Asp.Net*"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-or</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">Source </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-like</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">".net runtime*"</span></span></span></span><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">) }</span> </span></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">In this example I use the date property of the get-eventlog results to filter the events before passing them to the where-object cmdlet. This is done using the -before and -after switches. After that, the where-object command is used in the same way as the previous examples. </span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">The only difference is the two $_.Source properties are surround by brackets (). This is necessary so that the -or operator applies to only those two entries. I could add more $_.Source properties inside the brackets with additional -or operators if I wanted to increase this list beyond 2.</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Understanding the PowerShell operators is key to getting the results you want, this link contains useful information about operators</span><br />
<a href="http://technet.microsoft.com/en-gb/library/hh847759.aspx"><span style="font-family: Arial, Helvetica, sans-serif;">http://technet.microsoft.com/en-gb/library/hh847759.aspx</span></a><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Finally, you can export your results using any of PowerShell's export commands. I find export-csv works well:</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-EventLog</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-LogName</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">System</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Where-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">Message </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-like</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"*the service entered the stopped state*"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> } </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Export-Csv</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">C:\scripts\events.csv</span> </span></span></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<br />Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com11tag:blogger.com,1999:blog-394719478213759008.post-63141182242204951182015-01-12T02:48:00.001-08:002015-08-18T05:53:25.337-07:00PowerShell and IIS 6<h2>
<span style="font-family: Verdana, sans-serif;">IIS 6</span></h2>
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-ansi-language: EN-GB; mso-bidi-font-family: "Lucida Console"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB; mso-fareast-theme-font: minor-fareast;"><span style="color: black; font-family: Verdana, sans-serif;">Windows Server 2003 running IIS 6 does not support the latest version of PowerShell, and will not allow the use of the WebAdministration module or the most recent IIS cmdlets </span></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="font-family: Verdana, sans-serif; font-size: small;"></span><br />
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-ansi-language: EN-GB; mso-bidi-font-family: "Lucida Console"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB; mso-fareast-theme-font: minor-fareast;"><span style="color: black; font-family: Verdana, sans-serif; font-size: small;">(see this site for WebAdministration Cmdlets </span><a href="http://technet.microsoft.com/en-us/library/ee790599.aspx"><span style="color: blue; font-family: Verdana, sans-serif; font-size: small;">http://technet.microsoft.com/en-us/library/ee790599.aspx</span></a><span style="color: black; font-family: Verdana, sans-serif; font-size: small;">)</span><br />
<span style="font-family: Verdana, sans-serif; font-size: small;">
</span><span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /><span style="font-family: Verdana, sans-serif; font-size: small;">
</span><span style="font-size: small;"><span style="font-family: Verdana, sans-serif;"><span style="color: black;">To use PowerShell with IIS 6, you must use WMI, specifically the IIS WMI provider. To do this, use the Get-WmiObject cmdlet.<br />
</span>
</span></span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-ansi-language: EN-GB; mso-bidi-font-family: "Lucida Console"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB; mso-fareast-theme-font: minor-fareast;"><span style="color: black; font-family: Verdana; font-size: x-small;"><span style="color: black; font-family: Verdana, sans-serif; font-size: small;">The WMI namespace is root/Microsoftv2. The following link gives a list of classes that can be used:<br />
</span><a href="http://msdn.microsoft.com/en-us/library/ms525265(v=vs.90).aspx"><span style="font-family: Verdana, sans-serif; font-size: small;">http://msdn.microsoft.com/en-us/library/ms525265(v=vs.90).aspx</span></a></span></span></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-ansi-language: EN-GB; mso-bidi-font-family: "Lucida Console"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB; mso-fareast-theme-font: minor-fareast;"><span style="color: black; font-family: Verdana; font-size: x-small;"><span style="font-family: Verdana, sans-serif; font-size: small;">
</span></span></span></span><br />
</span></span><br />
<h4>
<span style="color: #444444; font-family: Verdana, sans-serif;">WMI Classes</span></h4>
<span style="color: black; font-family: Verdana, sans-serif;">I experimented with the different classes to find the properties that I needed. For example IISWebServer will give information on each site, IISWebServerSetting will give more detailed information on each site. IISWebVirtualDir will give information on virtual directories and applications and IISWebVirtualDirSetting will again give more detail on virtual directories and applications.<br />
<br />
For example, try running each of these commands, then view the results to see how the output changes.</span>
<br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">IIsWebServer</span> </span></span></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-ansi-language: EN-GB; mso-bidi-font-family: "Lucida Console"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB; mso-fareast-theme-font: minor-fareast;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: black; font-family: Verdana; font-size: x-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blue; font-size: x-small;">Get-WmiObject</span><span style="font-family: Lucida Console;"><span style="color: black; font-family: Lucida Console; font-size: x-small;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console; font-size: x-small;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="color: black; font-family: Lucida Console; font-size: x-small;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console; font-size: x-small;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="color: black; font-family: Lucida Console; font-size: x-small;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console; font-size: x-small;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="color: black; font-family: Lucida Console; font-size: x-small;"> </span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">IIsWebServerSetting</span></span></span></span></span></span></span></span></span></span></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="font-family: Lucida Console;"></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebVirtualDir</span></span></span></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="font-family: Lucida Console;"></span><span style="font-family: Lucida Console;"></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebVirtualDirSetting</span></span></span></span><br />
<br />
<span style="color: black; font-family: Verdana, sans-serif;">The next step is to use the where-object and select-object cmdlets to display only the results you want.</span><br />
<span style="color: black; font-family: Verdana, sans-serif;"></span><br />
<span style="color: black; font-family: Verdana, sans-serif;">Eg.</span><br />
<span style="color: black; font-family: Verdana, sans-serif;">This command will return a list of sites by site ID</span><br />
<span style="font-size: xx-small;"><span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebServer</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Select-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-ExpandProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="font-size: x-small;">Name</span> </span></span></span></span><br />
<br />
<span style="color: black; font-family: Verdana, sans-serif;">Whereas this command will return a specific site by specifying the site ID</span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebServer</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Where-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">Name </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-like</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"W3SVC/123456789</span></span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"</span></span></span></span><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;"> }</span> </span></span><br />
<br />
<span style="color: black; font-family: Verdana, sans-serif;">Also, this command will return a specific site by specifying the site ID along with all the settings for that site</span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="font-family: Lucida Console;"></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebServerSetting</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Where-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">Name </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-like</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"W3SVC/123456789</span></span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> }</span></span></span><br />
<span style="font-family: Lucida Console; font-size: x-small;"></span><br />
<span style="color: black; font-family: Verdana, sans-serif;">I was interested in listing all Physical Paths that were being used by each site in IIS. For this I need the IISWebVirtualDirSetting class and the Path property</span><br />
<span style="color: black; font-family: Verdana; font-size: x-small;"></span><br />
<span style="color: black; font-family: Verdana;">Eg.</span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebVirtualDirSetting</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Select-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-ExpandProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">Path</span> </span></span></span><br />
</span><span style="font-family: Verdana; font-size: x-small;"></span><br />
<span style="color: black; font-family: Verdana, sans-serif;">I can also add the -unique switch to eliminate any duplicates, and pipe the results to sort-object to put the output in alphabetical order</span><br />
<span style="color: black; font-family: Verdana, sans-serif;"></span><br />
<span style="color: black; font-family: Verdana, sans-serif;">Eg,</span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebVirtualDirSetting</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Select-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-ExpandProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">Path</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Unique</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">Sort-Object</span> </span></span></span><br />
</span><br />
<h4>
<span style="color: #444444;">Script</span></h4>
<span style="font-family: Verdana; font-size: x-small;"></span><br />
<span style="color: black; font-family: Verdana;">I put this all together into a script that will output the site name followed by a list of all Physical Paths in use by IIS. One of the challenges here was identifying a class that contained both the site name and physical path. This was not possible with one class, so I had to do it in stages.</span><br />
<br />
<span style="font-family: Verdana; font-size: x-small;"><span style="font-size: small;"><span style="color: black;">I obtained the</span> <span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">Name </span></span></span><span style="color: black;">property from</span> <span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebServer </span></span></span><span style="color: black;">class. This is the Site ID, and I can use this to filter both</span> <span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">ServerComment </span></span></span><span style="color: black;">property from</span> <span style="color: blueviolet; font-family: Lucida Console;">IIsWebServerSetting</span> <span style="color: black;">class for a user friendly website name, and the</span> <span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">path </span></span></span><span style="color: black;">property from</span> <span style="color: blueviolet; font-family: Lucida Console;">IIsWebVirtualDirSetting</span> <span style="color: black;">for the Physical Path</span></span><br />
</span><span style="font-family: Verdana, sans-serif;"></span><br />
<h3>
<span style="color: #444444; font-family: Verdana, sans-serif; font-size: small;">Script text</span></h3>
<span style="font-family: Verdana;"></span><br />
<span style="font-size: x-small;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$WebSiteID</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">=</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebServer</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Select-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-ExpandProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="color: blueviolet; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">Name</span> </span></span></span><br />
<br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;">ForEach</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> ( </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$Site</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;"><span style="color: darkblue; font-family: Lucida Console;">in</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$WebSiteID</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> )</span></span><br />
<span style="font-family: Lucida Console;"><br />
{</span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$WebSiteName</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">=</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebServerSetting</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Where-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">Name </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-like</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"</span></span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$site</span></span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> } </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Select-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Expandproperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">ServerComment</span></span></span><br />
<span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"></span></span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"></span></span></span><br />
<span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">write-host</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"`r`n"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$WebSiteName</span></span></span><br />
<span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"></span></span></span><br />
<span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$AppPath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">=</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebVirtualDirSetting</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Where-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> { </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$_</span></span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">.</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;">Name </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">-like</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"</span></span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$site</span></span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">/*"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> } </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">select</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-expandproperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">path</span></span></span><br />
<span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"></span></span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"></span></span></span><br />
<span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$AppPath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">=</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;">$AppPath</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">select-object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-unique</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">sort-object</span></span></span><br />
<span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: orangered;">$AppPath</span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"></span></span></span></span></span><br />
<span style="color: orangered; font-family: Lucida Console;"><span style="color: orangered; font-family: Lucida Console;"><span style="color: black; font-family: Lucida Console;">}</span></span></span></span><br />
<br />
<span style="color: black; font-family: Verdana, sans-serif;">One more thing to note is that I use -ExpandProperty rather than -Property to filter the results from the where-object and select-object cmdlets. This is to convert the output to a string. If I don't do this, I get the object itself, rather than a string containing the objects. To see what this actually means, try running these two commands and notice the difference in the results and the available methods and properties.</span><br />
<span style="font-family: Verdana; font-size: x-small;"></span><br />
<span style="font-family: Verdana;"><span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebServer</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Select-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Property</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">Name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-Member </span></span></span></span><br />
</span><span style="font-size: x-small;"></span><br />
<span style="font-size: x-small;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Get-WmiObject</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Namespace</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;"><span style="color: darkred; font-family: Lucida Console;">"root/MicrosoftIISv2"</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-Class</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">IIsWebServer</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;"><span style="color: blue; font-family: Lucida Console;">Select-Object</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;"><span style="color: navy; font-family: Lucida Console;">-ExpandProperty</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;"><span style="color: blueviolet; font-family: Lucida Console;">Name</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;"><span style="color: darkgrey; font-family: Lucida Console;">|</span></span></span><span style="font-family: Lucida Console;"><span style="font-family: Lucida Console;"> </span></span></span><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"><span style="color: blue; font-family: Lucida Console; font-size: xx-small;"><span style="font-size: x-small;">Get-Member</span> </span></span></span><br />
<br />
<span style="color: black; font-family: Verdana, sans-serif;"><span style="color: blue; font-family: "Lucida Console"; mso-ansi-language: EN-GB; mso-bidi-font-family: "Lucida Console"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB; mso-fareast-theme-font: minor-fareast;"></span></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-ansi-language: EN-GB; mso-bidi-font-family: "Lucida Console"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB; mso-fareast-theme-font: minor-fareast;"></span></span><br />
<br />
<br />
<br />
<br />
<br />
<br />
<span style="color: black; font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-ansi-language: EN-GB; mso-bidi-font-family: "Lucida Console"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB; mso-fareast-theme-font: minor-fareast;"></span></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-ansi-language: EN-GB; mso-bidi-font-family: "Lucida Console"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB; mso-fareast-theme-font: minor-fareast;"></span></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; mso-ansi-language: EN-GB; mso-bidi-font-family: "Lucida Console"; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-GB; mso-fareast-theme-font: minor-fareast;"></span></span><br />Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com0tag:blogger.com,1999:blog-394719478213759008.post-70327836502968651892014-05-30T03:28:00.001-07:002015-01-12T02:49:30.576-08:00Use PowerShell to set random periodic restart time on all Application Pools<span style="font-family: Verdana, sans-serif;">I have written a PowerShell script that will look at all IIS Application Pools, then set the recycle setting for Specific Time to a random time between 02.01 - 02.59.</span><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;">It will create a log file D:\AppPoolRestart.txt which contains the App Pool name and the recycle time.</span><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;">import-module webadministration </span><br />
<span style="font-family: Verdana, sans-serif;">$AppPools = get-item -Path IIS:\AppPools\* </span><br />
<span style="font-family: Verdana, sans-serif;">If (Test-Path D:\scripts\AppPoolRestart.txt) </span><br />
<span style="font-family: Verdana, sans-serif;">{ </span><br />
<span style="font-family: Verdana, sans-serif;">remove-item -path D:\AppPoolRestart.txt </span><br />
<span style="font-family: Verdana, sans-serif;">} </span><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;">ForEach ( $app in $appPools ) </span><br />
<span style="font-family: Verdana, sans-serif;">{ </span><br />
<span style="font-family: Verdana, sans-serif;">$minute = Get-Random -Minimum 1 -Maximum 59 </span><br />
<span style="font-family: Verdana, sans-serif;">$Name = $app.Name </span><br />
<span style="font-family: Verdana, sans-serif;">$time = "02:"+"$minute"+":00" </span><br />
<span style="font-family: Verdana, sans-serif;">Set-ItemProperty -Path IIS:\AppPools\$Name -Name Recycling.periodicRestart.schedule.collection -Value @{value="$time"} </span><br />
<span style="font-family: Verdana, sans-serif;">$output = "$Name"+" $time" </span><br />
<span style="font-family: Verdana, sans-serif;">out-file -Filepath D:\AppPoolRestart.txt -inputobject "$output" -append </span><br />
<span style="font-family: Verdana, sans-serif;">}</span> Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com1tag:blogger.com,1999:blog-394719478213759008.post-53573808091750381752011-11-24T08:23:00.001-08:002012-07-13T07:55:32.550-07:00SBS 2008 C drive runs out of space - shrink SharePoint database log file<span style="font-family: Arial, Helvetica, sans-serif;">I have seen serveral cases recently where a server running Small Business Server 2008 has run out of space on the C Drive. Using <a href="http://www.jam-software.com/freeware/" target="_blank">Tree Size</a>, I identified a folder which contained a large amount of data:</span><br />
<br />
<span style="font-family: Arial;">C:\Windows\SYSMSI</span><br />
<br />
<span style="font-family: Arial;">The area of this folder which contained all the data was</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">C:\Windows\SYSMSI\SSEE\MSSQL.2005\MSSQL\Data</span><br />
<br />
<span style="font-family: Arial;">This folder contained many SQL databases and log files, and after some research I discovered that my largest files were <b>Transactional Log</b> files for <b>Sharepoint</b>. </span><br />
<br />
<span style="font-family: Arial;">The biggest of these files was </span><br />
<span style="font-size: x-small;"><b><br /></b></span><br />
<span style="font-size: x-small;"><b><span style="font-family: Arial;">SharePoint_Config_ffffffff-ffff-ffff-ffff-fffffffffffffffffff_log.LDF</span></b></span><br />
<br />
<span style="font-family: Arial;"> and was up to 16Gb in size, but other culprits were</span><br />
<span style="font-size: x-small;"><b><span style="font-family: Arial;"><br /></span></b></span><br />
<span style="font-size: x-small;"><b><span style="font-family: Arial;">ShareWebDb_log.LDF</span></b></span><br />
<span style="font-size: x-small;"><b><span style="font-family: Arial;">WSS_Content_fffff..._log.LDF</span></b></span><br />
<br />
<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguoqROUje9kaDa7yClHFyUrEEMn9s6FsAvbaT3wSafgjXBkEcuMZNa1o3Je4hE8AqftwT042rDCMegpK6jMUgvHkqlsaB3hmyEdCbCktPFv_6foRpRjRlRfQXHBnv31Zd7MIGUlDbk-Bs/s1600/001.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguoqROUje9kaDa7yClHFyUrEEMn9s6FsAvbaT3wSafgjXBkEcuMZNa1o3Je4hE8AqftwT042rDCMegpK6jMUgvHkqlsaB3hmyEdCbCktPFv_6foRpRjRlRfQXHBnv31Zd7MIGUlDbk-Bs/s640/001.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif;">Large SharePoint log files</span></td></tr>
</tbody></table>
<br />
<br />
<br />
<br />
<br />
<span style="font-family: Arial;">All these files are log files which can easily be shrunk down to a manageable size. <b>SQL Server Management Studio</b> is required for this.</span><br />
<span style="font-family: Arial;"><br /></span><br />
<span style="font-family: Arial;">To run <b>SQL Management Studio</b>, select</span><br />
<br />
<span style="font-family: Arial;"><b>Start</b> > <b>All Programs</b> > <b>Microsoft SQL Server 2005</b> > <b>SQL Server Management Studio Express</b></span><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYNkqbBz0vwpdR8vpnzdqLQ9gRiy7CtlZBaQ_Q_8hR39HqD0DoVM5uSgxBKrzKIVgWjFI683QuXrDZiXI31g-_0yyl7CsrV2_ZAQbTsqmpWkBBd-jk0AzV5q9NBBzn6L4zKusaGNfGhas/s1600/002a.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYNkqbBz0vwpdR8vpnzdqLQ9gRiy7CtlZBaQ_Q_8hR39HqD0DoVM5uSgxBKrzKIVgWjFI683QuXrDZiXI31g-_0yyl7CsrV2_ZAQbTsqmpWkBBd-jk0AzV5q9NBBzn6L4zKusaGNfGhas/s1600/002a.jpg" /></a></div>
<span style="font-family: Arial;"><br /> </span><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<span style="font-family: Arial;">Server name is<br /><b>\\.\pipe\mssql$microsoft##ssee\sql\query</b><br /> </span><br />
<span style="font-family: Arial;">Then select <b>Connect</b></span><br />
<br />
<span style="font-family: Arial;"><span style="font-family: Arial;">Expand <strong>Databases</strong> and locate the datebase with the large log file</span></span><span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;"></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0z7pTH_X4Jn0xOozN2ufB5I5Y5KV9_MSDaPsQvEJMLxiT_yXDxsKFvuwhnSajFreE5Odi9Jsr1M3CIbOql36NmIePdi7Q26Gin-sLTUr50qXCha_w5RZGIMPG7yVptVnoi40zVUw3aYY/s1600/002a.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img $ca="true" border="0" height="478" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0z7pTH_X4Jn0xOozN2ufB5I5Y5KV9_MSDaPsQvEJMLxiT_yXDxsKFvuwhnSajFreE5Odi9Jsr1M3CIbOql36NmIePdi7Q26Gin-sLTUr50qXCha_w5RZGIMPG7yVptVnoi40zVUw3aYY/s640/002a.jpg" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<span style="font-family: Arial;"><br />Right click on the database and select New query<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqYtbTGHMtqqH4bORn3cLDtPJjrnmz-9WRNZWJ5OcBh5beZjhwpep7ZISTLe91yBkMfctwHCihyphenhyphenZRHemqy3HNnLG8YDGKAuU24eT8RzSyXMlIgEoqHlud9gP22pkoOG2D_r8anOe7_ZSE/s1600/003a.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img $ca="true" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqYtbTGHMtqqH4bORn3cLDtPJjrnmz-9WRNZWJ5OcBh5beZjhwpep7ZISTLe91yBkMfctwHCihyphenhyphenZRHemqy3HNnLG8YDGKAuU24eT8RzSyXMlIgEoqHlud9gP22pkoOG2D_r8anOe7_ZSE/s1600/003a.jpg" /></a><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />The query window will appear on the right. Enter the following text:<br /><br />ALTER DATABASE Database_name SET RECOVERY SIMPLE;<br />GO</span><span style="font-family: Arial;"></span><span style="font-family: Arial;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0A7t6wOc5NMRC5S4UX6KypLWwfLVsTl7p-8x2h89GbOgdQYYNGmDY36lAC8RXorNWm7cH0HiPPzHLatXTGeTpw0ZDh7e4izVug3AR7qG5CG_eZj5JkziLHXL7nw1PQTGooiiSme4UMZU/s1600/005.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img $ca="true" border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0A7t6wOc5NMRC5S4UX6KypLWwfLVsTl7p-8x2h89GbOgdQYYNGmDY36lAC8RXorNWm7cH0HiPPzHLatXTGeTpw0ZDh7e4izVug3AR7qG5CG_eZj5JkziLHXL7nw1PQTGooiiSme4UMZU/s640/005.jpg" width="640" /></a></div>
<span style="font-family: Arial;"><br /><br /><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: Arial, Helvetica, sans-serif;">Then click the <strong>Execute!</strong> button</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">If the database name contains a ' - ', you will get an error message (below). </span><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEic-iVAUKX0Ovdq4LEGy1OQ_eYCuI5uWB_QwC5CIk90_8QM4GB_JN3MY0_nKSc61OceMDYuzj2Noza-XzNYTpZNiXCm2ZY-4W-FP0ycdzXyziYPqmD2k70HL1OetLGz-6pgrpXGrIn1o8k/s1600/007.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img $ca="true" border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEic-iVAUKX0Ovdq4LEGy1OQ_eYCuI5uWB_QwC5CIk90_8QM4GB_JN3MY0_nKSc61OceMDYuzj2Noza-XzNYTpZNiXCm2ZY-4W-FP0ycdzXyziYPqmD2k70HL1OetLGz-6pgrpXGrIn1o8k/s640/007.jpg" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-family: Arial, Helvetica, sans-serif;">In this case, the database name must be surrounded by " ", eg:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">ALTER DATABASE "SharePoint_Config_29c26fca-17b8-48c1-9704-b869932abcb6" SET RECOVERY SIMPLE;</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">GO</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Then select Execute!</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiar3chycK7QY01Ycq3upHQA1Wr0Dz5a7rXdF5_FIfz_WUf3kFock4zSO6cTUGs0bhn3rD1kQoDm5Y_QrDDZdzHXkCBoUZJbvC2DUY35qK9vs-f47IKG1VxBZj9WMmC3PA7K_h0LqD6a0k/s1600/008.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img $ca="true" border="0" height="418" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiar3chycK7QY01Ycq3upHQA1Wr0Dz5a7rXdF5_FIfz_WUf3kFock4zSO6cTUGs0bhn3rD1kQoDm5Y_QrDDZdzHXkCBoUZJbvC2DUY35qK9vs-f47IKG1VxBZj9WMmC3PA7K_h0LqD6a0k/s640/008.jpg" width="640" /></a></div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">You should see a message which reads <strong>Commad(s) completed successfully</strong></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Next, Select the database</span></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Right click > Tasks > Shrink > Files</span></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: left;">
<br /></div>
<div class="separator" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzTfGeXhVnIQEjxQl2ZXKWnfegOLjIh4cBIruXSHu8Hcp9IekiFKAKfDMBmnKj3vqUT8JtIhV6q3UguSaCds4fPQQr_1S7thDFYEa9mD77Djpi7iQ-T4W-w1RftHWGClsdhyphenhyphenqtFt5pYms/s1600/009.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img $ca="true" border="0" height="436" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzTfGeXhVnIQEjxQl2ZXKWnfegOLjIh4cBIruXSHu8Hcp9IekiFKAKfDMBmnKj3vqUT8JtIhV6q3UguSaCds4fPQQr_1S7thDFYEa9mD77Djpi7iQ-T4W-w1RftHWGClsdhyphenhyphenqtFt5pYms/s640/009.jpg" width="640" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2HlP886aYi7KUsJ185VwzDqJYy3KOh8tUqI2_2XmqcvXJFGffH8ZJnvPYR_BPWc6jRUBD7inBy0CLzAQPU9IZIE5efZVuo0bEy42-jwRDnrJxv0-cP8uT2S3i9KnDVb8PMB5bQq0w2Wo/s1600/010.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img $ca="true" border="0" height="574" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2HlP886aYi7KUsJ185VwzDqJYy3KOh8tUqI2_2XmqcvXJFGffH8ZJnvPYR_BPWc6jRUBD7inBy0CLzAQPU9IZIE5efZVuo0bEy42-jwRDnrJxv0-cP8uT2S3i9KnDVb8PMB5bQq0w2Wo/s640/010.jpg" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Change File type to <strong>Log</strong></span></div>
<div class="separator" style="clear: both; text-align: left;">
<strong><br /></strong><span style="font-family: Arial, Helvetica, sans-serif;">Click OK</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheE8m9SEkCJtCWvwntxHgiYdwOPJlBwz3NmR6O7UglF6Mkq0cN8bFpX3DFJUBIT5cYxW6aEWeSSHVY7CXRJCBO2T1fD1CnI9wvKSb4so8LGV6i5zA1EPznGGskzDTaZ5kJ9aH-db9MtLE/s1600/011.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img $ca="true" border="0" height="573" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheE8m9SEkCJtCWvwntxHgiYdwOPJlBwz3NmR6O7UglF6Mkq0cN8bFpX3DFJUBIT5cYxW6aEWeSSHVY7CXRJCBO2T1fD1CnI9wvKSb4so8LGV6i5zA1EPznGGskzDTaZ5kJ9aH-db9MtLE/s640/011.jpg" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Once this process has completed, right click the database again and select <strong>New query</strong></span><br />
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Enter the following command (use " " around database_name if it contains ' - ')</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">ALTER DATABASE Database_name SET RECOVERY FULL;</span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">GO</span><br />
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">Execute!</span><br />
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVo1SoS81VwdtumxMXtvTl7J8Mibv_mq1w6FyFiuaY9c3EuaVPQti0XAk5rjh48p4THiKkqubtghSA-oKvpLgdaWYwOIbpTIFy5saMtvpuuba8QRURMSDxQ6-V3VzH0IbWhh4MNHYeoyg/s1600/012.jpg" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img $ca="true" border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVo1SoS81VwdtumxMXtvTl7J8Mibv_mq1w6FyFiuaY9c3EuaVPQti0XAk5rjh48p4THiKkqubtghSA-oKvpLgdaWYwOIbpTIFy5saMtvpuuba8QRURMSDxQ6-V3VzH0IbWhh4MNHYeoyg/s640/012.jpg" width="640" /></a></div>
<br />
<span style="font-family: "Arial", "sans-serif";">Browse to the folder location <br /><br /><span style="font-family: Arial, Helvetica, sans-serif;">C:\Windows\SYSMSI\SSEE\MSSQL.2005\MSSQL\Data</span><br /><br />and you should see a big difference in the size of the log file.</span><br />Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com19tag:blogger.com,1999:blog-394719478213759008.post-42807424461602444082011-08-02T09:22:00.000-07:002011-08-02T09:22:52.579-07:00Backup Exec job status switches between Queued and Loading Media<span style="font-family: Arial, Helvetica, sans-serif;">I needed to restore two files today, which were backed up to external hard disk using Backup Exec (v12.5). I connected the drive which contained the backup data, then ran an inventory. I then created a restore job, selected my files to restore, then started the job running. </span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">The Job Status changed to <strong>Queued</strong>, then to <strong>Loading Media</strong>, then back to <strong>Queued</strong> again. </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">This cycle continued, and the job would not start, it just remained cycling between Queued and Loading Media.</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">I resolved this bythe following process:</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Select <strong>Devices</strong>, then in the Devices panel, <em>right click</em> the server name, then select <strong>Pause</strong></span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"><em>Right click</em> the server name again, then select <strong>Backup Exec services</strong>, then select <strong>Restart all services</strong>.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Wait for all the services to restart, then click <strong>OK</strong> to the messages that are displayed.</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"><em>Right click</em> on the server name in <strong>Devices</strong> again, and <strong>remove the tick</strong> from <strong>Paused</strong></span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Restart all the services again.</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Once I had done this, I ran the backup job again (<em>Right click</em>, <strong>Retry Job Now</strong>), and the job completed without any problem.</span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Nick</span>Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com5tag:blogger.com,1999:blog-394719478213759008.post-23172464690898643202011-07-31T07:04:00.000-07:002011-07-31T07:04:41.397-07:00SBS 2008 - Move Exchange Database<div style="font-family: Arial,Helvetica,sans-serif;">Today I have been addressing a problem with a Small Business Server 2008; the C drive has run out of space. The first indication of a problem was when the users reported that external email had stopped being delivered. After some basic troubleshooting I noticed that space on the C drive was the problem. An SBS 2008 feature called "Back Pressure" was preventing any more mail being delivered, I will cover how I made a temporary fix to this problem in a separate post.</div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;">To help with the problem of low disk space on C:, I decided to move the Exchange database files and logs to the D: drive, which had plenty of free space. Having done this with Exchange 2003 I was pleasantly surprised to find that SBS 2008 included a wizard to automate the process. </div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;">Before starting this process, I have made sure that all users have closed down Outlook, and advised them that email will be unavailable until I let them know otherwise. First, I opened the <b>SBS Console</b>, then selected <b>Backup and Server Storage</b>, then the <b>Server Storage</b> tab. I can see my available drives, along with a warning that C: is low on space. </div><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvhZYkb-1FxImyUy1ZTQwW4LxZtQBaudhQoLsUyygS_JL-zykCUHGJTBn5cniarfzrNodRbAgklWPZapAHA7SC7gBSy_kK2fy3SIVChGwgC6mfYQ6Rvwv4yJPA1PUF1CqgnsEBNR-v1bM/s1600/001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="231" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvhZYkb-1FxImyUy1ZTQwW4LxZtQBaudhQoLsUyygS_JL-zykCUHGJTBn5cniarfzrNodRbAgklWPZapAHA7SC7gBSy_kK2fy3SIVChGwgC6mfYQ6Rvwv4yJPA1PUF1CqgnsEBNR-v1bM/s320/001.jpg" width="320" /></a></div><br />
<div style="font-family: Arial,Helvetica,sans-serif;">This clearly showed the problem. Storage Tasks on the right hand side included the option <b>Move Exchange Server Data</b> - the first on the list. After selecting this, the <b>Move Exchange Server Data </b>wizard starts, and I get a message saying <b>Checking you server... This may take several minutes</b>. And it does, but not too long. </div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;">When it is ready, I get the option to back up my data before proceeding. </div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx3cr-IxxOPy3sE9K8mLA9O0soVu5S8_LElF6MwI2j2jn7NQebc0BV-RcuNZbIGrzcatDjwc91WMvtGiA66mb-f2XUFBTph90Nu-Z6TaQfcfZD-skg1peQDH28YHq3_MvzqCP9p8hkC24/s1600/002.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="258" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx3cr-IxxOPy3sE9K8mLA9O0soVu5S8_LElF6MwI2j2jn7NQebc0BV-RcuNZbIGrzcatDjwc91WMvtGiA66mb-f2XUFBTph90Nu-Z6TaQfcfZD-skg1peQDH28YHq3_MvzqCP9p8hkC24/s320/002.jpg" width="320" /></a></div><br />
<br />
<br />
<br />
<br />
<br />
<div style="font-family: Arial,Helvetica,sans-serif;">I've not done this process before, so decide a current backup would be a good idea, so I select <b>Yes</b>, and the backup begins. This server is configured to use SBS 2008 backup feature, and already has an external drive attached for backup. I presume my current backup settings are used. If the server backup was not in use, I expect I would have to enter some additional information at this point.</div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;">The backup takes a while, about 30 minutes. Once it is done, I am now ready to choose the new location for my Exchange data.</div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4n255Y5escgitfhlC6yH2qIzumEmCwemkFSiceacE7JRrjkTGc4_G5frtzMfj83m4MfhmEhD5-z7Lar1sS0bt4DGqWbj4Ak7l8Q059vRGRE4Pn3OCgLtroM6k8vq2hiJUgBzZbYWVIxI/s1600/003.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="258" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4n255Y5escgitfhlC6yH2qIzumEmCwemkFSiceacE7JRrjkTGc4_G5frtzMfj83m4MfhmEhD5-z7Lar1sS0bt4DGqWbj4Ak7l8Q059vRGRE4Pn3OCgLtroM6k8vq2hiJUgBzZbYWVIxI/s320/003.jpg" width="320" /></a></div><br />
<br />
<br />
<br />
<br />
<br />
<div style="font-family: Arial,Helvetica,sans-serif;">There is no option to choose the location or path for the new data location. I am only presented with a list of available drives. In my case, the D: drive. I leave this highlighted, then select <b>Move</b>.</div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><span style="font-family: Arial,Helvetica,sans-serif;">The data move does not take long. </span><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7jUHBFvqxtuWQJcEvmraj3QGWaEcGqhCprvljfPT6FmedCMHeIecIulw9C7yZtrN3sxjnUo8O2KRTDT6VZ_tAQxVgXSIJ2yEi3XRdfzuDnfutMWgN_xITGSsgEynd3JOIPD2rInEEwv8/s1600/004.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="258" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7jUHBFvqxtuWQJcEvmraj3QGWaEcGqhCprvljfPT6FmedCMHeIecIulw9C7yZtrN3sxjnUo8O2KRTDT6VZ_tAQxVgXSIJ2yEi3XRdfzuDnfutMWgN_xITGSsgEynd3JOIPD2rInEEwv8/s320/004.jpg" width="320" /></a></div><br />
<div style="font-family: Arial,Helvetica,sans-serif;">Once I see the message telling me the data move was successful, I select <b>Finish</b>, then test email by asking on of the users to open Outlook. Everything appears fine.</div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><span style="font-family: Arial,Helvetica,sans-serif;">I check the D: drive and can see the new data location is </span><b style="font-family: Arial,Helvetica,sans-serif;">D:\Program Files\Microsoft\Exchange Server</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGIFicM4pOcMowi-btgO9uZX0YvdCwlptygEBPlhIvMCB-lcmsxlt3Fv_4klOVzQzLSggH1AD514oXOvTR1_jDM_Dedq5YI6BXTDSz41zuvS-i067Pl_8zuvXIc18jihzy6xnvLgrPICY/s1600/005.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="181" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGIFicM4pOcMowi-btgO9uZX0YvdCwlptygEBPlhIvMCB-lcmsxlt3Fv_4klOVzQzLSggH1AD514oXOvTR1_jDM_Dedq5YI6BXTDSz41zuvS-i067Pl_8zuvXIc18jihzy6xnvLgrPICY/s320/005.jpg" width="320" /></a></div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;">I am slightly surprised that I have not reclaimed more space by moving the Exchange files. After using TreeSize to scan the C: drive, I discover that two folders are taking up most of my space:</div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;">C:\Windows\SYSMSI - 11.5 Gb</div><span style="font-family: Arial,Helvetica,sans-serif;">C:\Windows\winsxs - 12.5 Gb</span><br />
<div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;">I will write how I solved the problem of these two folders taking up so much space in a separate post.</div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><span style="font-family: Arial,Helvetica,sans-serif;">Nick</span>Network_Nickhttp://www.blogger.com/profile/10720378688584985106noreply@blogger.com1