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

<channel>
	<title>Thomas Maurer (tm) &#187; Microsoft Powershell</title>
	<atom:link href="http://www.thomasmaurer.ch/tag/microsoft-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thomasmaurer.ch</link>
	<description>Just another private cloud weblog</description>
	<lastBuildDate>Wed, 08 Feb 2012 17:42:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Powershell: Changing registry key value</title>
		<link>http://www.thomasmaurer.ch/2010/08/powershell-changing-registry-key-value/</link>
		<comments>http://www.thomasmaurer.ch/2010/08/powershell-changing-registry-key-value/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 16:00:21 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Windows Server 2003]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Changing]]></category>
		<category><![CDATA[get-psdrive]]></category>
		<category><![CDATA[HKLM]]></category>
		<category><![CDATA[key value]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[Microsoft Powershell]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[registry]]></category>
		<category><![CDATA[registry key value]]></category>
		<category><![CDATA[Set-ItemProperty]]></category>
		<category><![CDATA[Set-Location]]></category>
		<category><![CDATA[Values]]></category>
		<category><![CDATA[Windows Registry]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=907</guid>
		<description><![CDATA[After posting Pagefile size bigger than 4095MB on Windows Server 2003 I had the Idea to change this registry values with powershell. First start powershell You can get all PS Drives with the command Get-PSDrive Now you see the drive &#8230; <a href="http://www.thomasmaurer.ch/2010/08/powershell-changing-registry-key-value/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img class="aligncenter size-medium wp-image-621" title="Powershell Header" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42-300x70.png" alt="Powershell Header" width="300" height="70" /></p>
<p>After posting <a title="Pagefile size bigger than 4095MB on Windows Server 2003" href="http://www.thomasmaurer.ch/2010/08/pagefile-size-bigger-than-4095mb-on-windows-server-2003/" target="_blank">Pagefile size bigger than 4095MB on Windows Server 2003</a> I had the Idea to change this registry values with powershell.</p>
<ol>
<li>First start powershell</li>
<li>You can get all PS Drives with the command
<pre>Get-PSDrive</pre>
<p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2010/08/Screen-shot-2010-08-02-at-16.41.23.png" rel="lightbox[907]"><img class="aligncenter size-medium wp-image-909" title="Get-PSDrive" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/08/Screen-shot-2010-08-02-at-16.41.23-300x152.png" alt="Get-PSDrive" width="300" height="152" /></a></li>
<li>Now you see the drive HKLM which stands for HKEY_LOCAL_MACHINE</li>
<li>Open this Registry Key
<pre>Set-Location 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management'</pre>
</li>
<li>With this command you get all the key values
<pre>Get-ItemProperty -path .</pre>
</li>
<li> With the next command you can set the the key value
<pre>Set-ItemProperty -path . -name "PagingFiles" -value "D:\pagefile1\pagefile.sys 4096 4096"</pre>
</li>
</ol>
<p>And now the simple way with multiple entries:</p>
<pre>
$values = @"
D:\pagefile1\pagefile.sys 4096 4096
D:\pagefile2\pagefile.sys 4096 4096
"@
$keys = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
$name = "PagingFiles"
Set-ItemProperty -path $keys -name $name -value $values
</pre>
<div class="shr-publisher-907"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2010/08/powershell-changing-registry-key-value/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Powershell: Count Sharepoint Sites on Sharepoint Server 2010</title>
		<link>http://www.thomasmaurer.ch/2010/07/powershell-count-sharepoint-sites-on-sharepoint-server-2010/</link>
		<comments>http://www.thomasmaurer.ch/2010/07/powershell-count-sharepoint-sites-on-sharepoint-server-2010/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 14:32:39 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Windows Server 2008 R2]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Genotec]]></category>
		<category><![CDATA[Genotec AG]]></category>
		<category><![CDATA[get-SPsites]]></category>
		<category><![CDATA[Hosted Sharepoint]]></category>
		<category><![CDATA[Hosted Sharepoint 2010]]></category>
		<category><![CDATA[Microsoft Powershell]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Sharepoint 2010]]></category>
		<category><![CDATA[Sharepoint Foundation Server 2010]]></category>
		<category><![CDATA[Sharepoint Server 2010]]></category>
		<category><![CDATA[Site Collections]]></category>
		<category><![CDATA[Sites]]></category>
		<category><![CDATA[SPSites]]></category>
		<category><![CDATA[Windows Powershell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=880</guid>
		<description><![CDATA[This is a very small line of code to count Sharepoint 2010 Site Collections with Powershell. (Get-SPSite -Limit all).Count By the way, we at Genotec AG are offering a Hosted Sharepoint 2010 solution based on Powershell automation.]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" rel="lightbox[880]"><img class="aligncenter size-full wp-image-621" title="Powershell Header" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" alt="Powershell Header" width="440" height="104" /></a></p>
<p>This is a very small line of code to count <a title="Sharepoint 2010" href="http://sharepoint.microsoft.com" target="_blank">Sharepoint 2010</a> Site Collections with Powershell.</p>
<pre>
(Get-SPSite -Limit all).Count
</pre>
<p>By the way, we at Genotec AG are offering a <a title="Genotec Hosted Sharepoint 2010" href="http://www.genotec.ch/de/application-hosting/sharepoint/index.html" target="_blank">Hosted Sharepoint 2010 </a>solution based on Powershell automation.</p>
<div class="shr-publisher-880"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2010/07/powershell-count-sharepoint-sites-on-sharepoint-server-2010/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Powershell: Working with XML part 2</title>
		<link>http://www.thomasmaurer.ch/2010/07/powershell-working-with-xml-part-2/</link>
		<comments>http://www.thomasmaurer.ch/2010/07/powershell-working-with-xml-part-2/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 13:42:04 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Server Core]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[Add Data to XML]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[Microsoft Powershell]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Remove]]></category>
		<category><![CDATA[Remove data from XML]]></category>
		<category><![CDATA[Save]]></category>
		<category><![CDATA[Save XML Object]]></category>
		<category><![CDATA[Saving data to XML]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Windows Powershell]]></category>
		<category><![CDATA[Working]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XML Powershell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=863</guid>
		<description><![CDATA[After my first post (Powershell: Parsing XML part 1) about working with XML and Powershell, I have create this second post which describes how to create a XML file, Add content to the XML file, remove content from the XML &#8230; <a href="http://www.thomasmaurer.ch/2010/07/powershell-working-with-xml-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" rel="lightbox[863]"><img class="aligncenter size-full wp-image-621" title="Powershell Header" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" alt="Powershell Header" width="440" height="104" /></a></p>
<p>After my first post (<a href="http://www.thomasmaurer.ch/2010/06/powershell-parsing-xml-part-1/">Powershell: Parsing XML part 1</a>) about working with XML and Powershell, I have create this second post which describes how to create a XML file, Add content to the XML file, remove content from the XML file and save the XML objects as a file.</p>
<p>While I was writing a script which communicates with a webserver, I realized that I need some error handling if the server can not anwser a request from my script. For example if the webserver is down or has to much load.</p>
<p>I created a little retry part (<a href="http://www.thomasmaurer.ch/2010/07/powershell-simple-retry-logic/" target="_self">Powershell: Simple retry logic</a>) which retries several times. But if the Server is down for several hours or days your script hangs in a retry loop. Obviously this cant be the solution. After a little bit of thinking a decided to write the data, which I was trying to send, down in a XML file. And the next time the script runs it reads the XML file and tries to send the data again.</p>
<p>Thats the story behind my idea for saving data in a XML file.</p>
<h2>Creating a XML object</h2>
<pre>
[XML]$FruitList = "&lt;Box&gt;
&lt;Fruit&gt;
&lt;Name&gt;Banana&lt;/Name&gt;
&lt;Color&gt;yellow&lt;/Color&gt;
&lt;/Fruit&gt;
&lt;/Box&gt;"
</pre>
<h2>Save a XML object as a XML file</h2>
<pre>
$FruitList.Save("./myfruitlist.xml")
</pre>
<p>XML:</p>
<pre>
&lt;Box&gt;
	&lt;Fruit&gt;
		&lt;Name&gt;Banana&lt;/Name&gt;
		&lt;Color&gt;yellow&lt;/Color&gt;
	&lt;/Fruit&gt;
&lt;/Box&gt;
</pre>
<h2>Open a saved XML file</h2>
<pre>
[xml]$FruitList = Get-Content ./myfruitlist.xml
</pre>
<h2>Add data to XML object and save it in a XML file</h2>
<pre>
# Copy Object from Banana
[Object]$CopyFruit = FruitList.Box.Fruit | Where-Object {$_.Name -eq "Banana"}
$NewFruit = $CopyFruit.Clone()
# Add Fruit to new Object
$NewFruit.Name = "Apple"
$NewFruit.Color = "green"
# Add Fruit to XML Object
$FruitList.Box.AppendChild($NewFruit)
#Save to XML object ot XML file
$FruitList.Save("./myfruitlist.xml")
</pre>
<p>XML:</p>
<pre>
&lt;Box&gt;
	&lt;Fruit&gt;
		&lt;Name&gt;Banana&lt;/Name&gt;
		&lt;Color&gt;yellow&lt;/Color&gt;
	&lt;/Fruit&gt;
	&lt;Fruit&gt;
		&lt;Name&gt;Apple&lt;/Name&gt;
		&lt;Color&gt;green&lt;/Color&gt;
	&lt;/Fruit&gt;
&lt;/Box&gt;</pre>
<h2>Change data from XML Object and save it as XML file</h2>
<pre>
# Change Apple Color
$FruitList.Box.Fruit | Where-Object {$_.Name -eq "Apple"} | ForEach-Object { $_.Color = "red" }
#Save to XML object ot XML file
$FruitList.Save("./myfruitlist.xml")
</pre>
<p>XML:</p>
<pre>
&lt;Box&gt;
	&lt;Fruit&gt;
		&lt;Name&gt;Banana&lt;/Name&gt;
		&lt;Color&gt;yellow&lt;/Color&gt;
	&lt;/Fruit&gt;
	&lt;Fruit&gt;
		&lt;Name&gt;Apple&lt;/Name&gt;
		&lt;Color&gt;red&lt;/Color&gt;
	&lt;/Fruit&gt;
&lt;/Box&gt;</pre>
<h2>Remove data from XML Object and save it as XML file</h2>
<pre>
# Remove Banana from Object
$RemoveFruit = $FruitList.Box.Fruit | Where-Object {$_.Name -eq "Banana"}
$FruitList.Box.RemoveChild($RemoveFruit)
#Save to XML object ot XML file
$FruitList.Save("./myfruitlist.xml")
</pre>
<p>XML:</p>
<pre>
&lt;Box&gt;
	&lt;Fruit&gt;
		&lt;Name&gt;Apple&lt;/Name&gt;
		&lt;Color&gt;green&lt;/Color&gt;
	&lt;/Fruit&gt;
&lt;/Box&gt;</pre>
<div class="shr-publisher-863"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2010/07/powershell-working-with-xml-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Powershell: Count your Code lines</title>
		<link>http://www.thomasmaurer.ch/2010/07/powershell-count-your-code-lines/</link>
		<comments>http://www.thomasmaurer.ch/2010/07/powershell-count-your-code-lines/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 09:26:36 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Count]]></category>
		<category><![CDATA[Count lines]]></category>
		<category><![CDATA[Get-ChildItem]]></category>
		<category><![CDATA[Microsoft Powershell]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[ps1]]></category>
		<category><![CDATA[Select-String]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Powershell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=860</guid>
		<description><![CDATA[After Coding some lines in a lot of different files you wanna know how much lines you have coded. There are two (I am sure there are even more) ways to do that. The first one is to get the &#8230; <a href="http://www.thomasmaurer.ch/2010/07/powershell-count-your-code-lines/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" rel="lightbox[860]"><img class="aligncenter size-full wp-image-621" title="Powershell Header" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" alt="Powershell Header" width="440" height="104" /></a></p>
<p>After Coding some lines in a lot of different files you wanna know how much lines you have coded. There are two (I am sure there are even more) ways to do that. The first one is to get the content of the files (<code>Get-Content</code>) and count the lines in there.</p>
<p>The other way and the fasterway is with <code>Select-String</code>:</p>
<pre>(Get-ChildItem -Include *.ps1 -Recurse | Select-String -pattern .).Count</pre>
<div class="shr-publisher-860"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2010/07/powershell-count-your-code-lines/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Powershell: Simple retry logic</title>
		<link>http://www.thomasmaurer.ch/2010/07/powershell-simple-retry-logic/</link>
		<comments>http://www.thomasmaurer.ch/2010/07/powershell-simple-retry-logic/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 15:13:53 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[do while]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[Loop]]></category>
		<category><![CDATA[Microsoft Powershell]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Retry]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Powershell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=834</guid>
		<description><![CDATA[I am working at some larger powershell scripts right now and so I needed to create a simple retry logic for sending web request to a server. # Comment $Stoploop = $false [int]$Retrycount = &#34;0&#34; do { try { Scripts &#8230; <a href="http://www.thomasmaurer.ch/2010/07/powershell-simple-retry-logic/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" rel="lightbox[834]"><img class="aligncenter size-full wp-image-621" title="Powershell Header" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" alt="Powershell Header" width="440" height="104" /></a></p>
<p>I am working at some larger powershell scripts right now and so I needed to create a simple retry logic for sending web request to a server.</p>
<p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2010/07/Screen-shot-2010-07-23-at-17.08.09.png" rel="lightbox[834]"><img class="aligncenter size-medium wp-image-835" title="Powershell retry loop" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/07/Screen-shot-2010-07-23-at-17.08.09-300x166.png" alt="Powershell retry loop" width="300" height="166" /></a></p>
<p><span id="more-834"></span></p>
<pre>
<pre>
# Comment
$Stoploop = $false
[int]$Retrycount = &quot;0&quot;

do {
	try {
		Scripts Commands here
		Write-Host &quot;Job completed&quot;
		$Stoploop = $true
		}
	catch {
		if ($Retrycount -gt 3){
			Write-Host &quot;Could not send Information after 3 retrys.&quot;
			$Stoploop = $true
		}
		else {
			Write-Host &quot;Could not send Information retrying in 30 seconds...&quot;
			Start-Sleep -Seconds 30
			$Retrycount = $Retrycount + 1
		}
	}
}
While ($Stoploop -eq $true)
</pre>
</pre>
<div class="shr-publisher-834"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2010/07/powershell-simple-retry-logic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell: Get Sharepoint 2010 Site Collection Storage Usage</title>
		<link>http://www.thomasmaurer.ch/2010/07/powershell-get-sharepoint-2010-site-collection-storage-usage/</link>
		<comments>http://www.thomasmaurer.ch/2010/07/powershell-get-sharepoint-2010-site-collection-storage-usage/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 14:30:45 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Add-PSSnapin]]></category>
		<category><![CDATA[get-member]]></category>
		<category><![CDATA[get-spsite]]></category>
		<category><![CDATA[Microsoft Powershell]]></category>
		<category><![CDATA[Microsoft Sharepoint 2010]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Sharepoint 2010]]></category>
		<category><![CDATA[SharePoint 2010 Management Shell]]></category>
		<category><![CDATA[Site Collection Storage]]></category>
		<category><![CDATA[Site Collection Usage]]></category>
		<category><![CDATA[Usage.Storage]]></category>
		<category><![CDATA[Windows Powershell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=773</guid>
		<description><![CDATA[If you need to get the Storage Usage from a Sharepoint 2010 Site Collection, you can do this with Powershell. 1. Start SharePoint 2010 Management Shell or Powershell with the Sharepoint Snapin by: Add-PSSnapin "Microsoft.SharePoint.PowerShell" 2. Create a new Object &#8230; <a href="http://www.thomasmaurer.ch/2010/07/powershell-get-sharepoint-2010-site-collection-storage-usage/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>If you need  to get the Storage Usage from a Sharepoint 2010 Site Collection, you can do this with Powershell.</p>
<p style="text-align: center;"><a href="http://www.thomasmaurer.ch/wp-content/uploads/2010/07/Screen-shot-2010-07-12-at-16.27.31.png" rel="lightbox[773]"><img class="size-full wp-image-776 aligncenter" title="Current Storage Used" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/07/Screen-shot-2010-07-12-at-16.27.31.png" alt="Current Storage Used" width="447" height="143" /></a></p>
<p>1. Start SharePoint 2010 Management Shell or Powershell with the Sharepoint Snapin by:</p>
<p><code>Add-PSSnapin "Microsoft.SharePoint.PowerShell"</code></p>
<p>2. Create a new Object for a Site Collection:</p>
<p><code>$MySite = Get-SPSite http://my.sharepoint.com</code></p>
<p>3. You can now check the members of the $MySite Object:</p>
<p><code>$MySite | Get-Member</code> (You could also use: <code>Get-SPSite http://mysite.sharepoint.com | Get-Member</code>)</p>
<p><a href="http://www.thomasmaurer.ch/wp-content/uploads/2010/07/Screen-shot-2010-07-12-at-16.21.16.png" rel="lightbox[773]"><img class="alignleft size-full wp-image-775" title="get-spsite http://mysite.sharepoint.com | get-member" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/07/Screen-shot-2010-07-12-at-16.21.16.png" alt="get-spsite http://mysite.sharepoint.com | get-member" width="702" height="913" /></a></p>
<p>4. Now you get an output with a lot of member properties of this Site Collection Object. And you can see there is a member property called Usage, I think thats the right property. Now lets see what we get here:</p>
<p><code>$MySite.Usage</code></p>
<p>retruns:</p>
<p><code>Storage           : 1775819<br />
Bandwidth         : 0<br />
Visits            : 0<br />
Hits              : 0<br />
DiscussionStorage : 0</code></p>
<p>Ah there is a Storage property, lets use this to only get the used Storage:</p>
<p><code>$MySite.Usage.Storage</code></p>
<p>this returns the Storage Space in Bytes. Not really use full, so we get this in Megabytes:</p>
<p><code>$MySite.Usage.Storage / 1MB</code></p>
<p>returns:</p>
<p><code>1.6935....</code></p>
<div class="shr-publisher-773"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2010/07/powershell-get-sharepoint-2010-site-collection-storage-usage/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Powershell: check variable for null</title>
		<link>http://www.thomasmaurer.ch/2010/07/powershell-check-variable-for-null/</link>
		<comments>http://www.thomasmaurer.ch/2010/07/powershell-check-variable-for-null/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 20:18:58 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[check $null]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[if null]]></category>
		<category><![CDATA[Microsoft Powershell]]></category>
		<category><![CDATA[Null]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Variable]]></category>
		<category><![CDATA[Windows Powershell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=763</guid>
		<description><![CDATA[If your working a lot with parameters and inputs you need to check if variables have the right value and are not &#8220;null&#8221;. The normal if -eq &#8220;$null&#8221; doesn&#8217;t work: if ($varibalename -eq $null) { Write-Host "variable is null" } Now &#8230; <a href="http://www.thomasmaurer.ch/2010/07/powershell-check-variable-for-null/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p style="text-align: center;"><a href="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" rel="lightbox[763]"><img class="size-full wp-image-621 aligncenter" title="Powershell Header" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" alt="Powershell Header" width="440" height="104" /></a></p>
<p>If your working a lot with parameters and inputs you need to check if variables have the right value and are not &#8220;null&#8221;.</p>
<p>The normal if -eq &#8220;$null&#8221; doesn&#8217;t work:</p>
<p><code><del datetime="2010-07-09T20:19:51+00:00">if ($varibalename -eq $null) { Write-Host "variable is null" }</del></code></p>
<p>Now how you can check that (check if $variablename has $null as value):</p>
<p><code>if (!$variablename) { Write-Host "variable is null" }</code></p>
<p>And here if you wanna check if $variablename has any value except $null:</p>
<p><code>if ($variablename) { Write-Host "variable is NOT null" }</code></p>
<div class="shr-publisher-763"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2010/07/powershell-check-variable-for-null/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Powershell: Send Tweet</title>
		<link>http://www.thomasmaurer.ch/2010/06/powershell-send-tweet/</link>
		<comments>http://www.thomasmaurer.ch/2010/06/powershell-send-tweet/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 13:26:22 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Microsoft Powershell]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[send]]></category>
		<category><![CDATA[Send Tweet]]></category>
		<category><![CDATA[Tweet]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Windows Powershell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=732</guid>
		<description><![CDATA[For some reason your Powershell script should send a Tweet. With this function Powershell will send a message to Twitter. function Send-Tweet($Message) { #Twitter Login $Twitter_UserName = "yourname" $Twitter_Password = "yourpassword" $Twitter_URL = "https://twitter.com/statuses/update.xml?status=" $Twitter_Request = [System.Net.WebRequest]::Create($Twitter_URL + $Message) $Twitter_Request.credentials= &#8230; <a href="http://www.thomasmaurer.ch/2010/06/powershell-send-tweet/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img class="aligncenter size-full wp-image-621" title="Powershell Header" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" alt="Powershell Header" width="440" height="104" /></p>
<p>For some reason your Powershell script should send a Tweet. With this function Powershell will send a message to <a href="http://www.twitter.com/thomasmaurer" target="_blank">Twitter</a>.</p>
<p><code>function Send-Tweet($Message)<br />
{<br />
#Twitter Login<br />
$Twitter_UserName = "yourname"<br />
$Twitter_Password = "yourpassword"<br />
$Twitter_URL = "https://twitter.com/statuses/update.xml?status="</code></p>
<p><code> </code></p>
<p><code>$Twitter_Request = [System.Net.WebRequest]::Create($Twitter_URL + $Message)<br />
$Twitter_Request.credentials= New-Object System.Net.NetworkCredential($Twitter_UserName,$Twitter_Password)<br />
$Twitter_Request.method= "POST"<br />
$Twitter_Request.contentType = "application/x-www-form-urlencoded"<br />
$Twitter_Request.GetResponse().statusCode # return the status code of the request<br />
}</code></p>
<p>You can now call this function and add a message</p>
<p><code>Send-Tweet "This is my first Tweet from Powershell"</code></p>
<p><img class="aligncenter size-full wp-image-733" title="Twitter" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/06/twitter-icon-for-a-fluid-app-von-mfilej.jpg" alt="Twitter" width="240" height="240" /></p>
<p>If you need a interactive script you can simply use this (seen by <a href="http://www.bhargavs.com/index.php/2010/03/16/send-a-tweet-from-powershell/" target="_blank">Bhargav&#8217;s IT Playground</a>)</p>
<p><code>function Send-Tweet($Message,$UserName){<br />
if($Message-eq$null){$Message=Read-Host"Enter your tweet"}<br />
if($Username-eq$null){$Username=read-host"Enter your twitter username"}<br />
if($Password-eq$null)<br />
{<br />
$Password=read-host-assecurestring"Enter your twitter password"<br />
$marshal=[Runtime.InteropServices.Marshal]<br />
$Password=$marshal::PtrToStringAuto($marshal::SecureStringToBSTR($Password))<br />
}<br />
$url="https://twitter.com/statuses/update.xml?status=$Message"<br />
$request=[System.Net.WebRequest]::Create($url)<br />
$request.credentials=New-Object System.Net.NetworkCredential($UserName,$Password)<br />
$request.method="POST"<br />
$request.contentType ="application/x-www-form-urlencoded"<br />
$request.GetResponse().statusCode # return the status code of the request}</code></p>
<div class="shr-publisher-732"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2010/06/powershell-send-tweet/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Powershell: Parsing XML part 1</title>
		<link>http://www.thomasmaurer.ch/2010/06/powershell-parsing-xml-part-1/</link>
		<comments>http://www.thomasmaurer.ch/2010/06/powershell-parsing-xml-part-1/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 14:51:59 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[get-content]]></category>
		<category><![CDATA[Microsoft Powershell]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[parsing XML]]></category>
		<category><![CDATA[parsing XML with Powershell]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Powershell Commands]]></category>
		<category><![CDATA[read XML]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=724</guid>
		<description><![CDATA[In my company we started to use XML files as configuration files. So we use it for some configurations of servers or automation for our robots. In Powershell there is a pretty easy way for parsing XML. In Powershell there &#8230; <a href="http://www.thomasmaurer.ch/2010/06/powershell-parsing-xml-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p style="text-align: center;"><a href="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" rel="lightbox[724]"><img class="aligncenter size-medium wp-image-621" title="Powershell Header" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42-300x70.png" alt="Powershell Header" width="300" height="70" /></a></p>
<p>In my company we started to use XML files as configuration files. So we use it for some configurations of servers or automation for our robots. In Powershell there is a pretty easy way for parsing XML. In Powershell there is an object type for XML, so you just can use the get-content Cmdlet to read the XML file into the object.</p>
<p><code>
<pre></pre>
<p>$xmldata = get-content "C:\XMLFiles\mydata.xml"</code></p>
<p>When you create a function for reading XML files you also can set the XML object to global.</p>
<p><code>
<pre></pre>
<p>$global:xmldata = get-content "C:\XMLFiles\mydata.xml</code></p>
<p>Now $xmldata is a object which includes all the data of the mydata.xml.</p>
<p>Lets view the content of the mydata.xml file. We need this to understand the following commands.</p>
<blockquote><p>&lt;TodoList ID = &#8220;Week21&#8243;&gt;</p>
<p>&lt;Task action=&#8221;create&#8221; ID=&#8221;1&#8243;&gt;<br />
&lt;Name&gt;Peter&lt;/Name&gt;<br />
&lt;Dept&gt;Administration&lt;/Dept&gt;<br />
&lt;email&gt;peter@contoso.com&lt;/email&gt;<br />
&lt;/Task&gt;</p>
<p>&lt;Task action=&#8221;create&#8221; ID=&#8221;2&#8243;&gt;<br />
&lt;Name&gt;Thomas&lt;/Name&gt;<br />
&lt;Dept&gt;Administration&lt;/Dept&gt;<br />
&lt;email&gt;thomas@contoso.com&lt;/email&gt;<br />
&lt;/Task&gt;</p>
<p>&lt;Task action=&#8221;delete&#8221; ID=&#8221;3&#8243;&gt;<br />
&lt;Name&gt;Steve&lt;/Name&gt;<br />
&lt;Dept&gt;IT&lt;/Dept&gt;<br />
&lt;email&gt;steve@contoso.com&lt;/email&gt;<br />
&lt;/Task&gt;</p>
<p>&lt;/TodoList&gt;</p></blockquote>
<p>Now we wanna get all unique Accounts listed</p>
<p><code>$xmldata.TodoList.Task | %{$_.Name} | select-object -unique</code></p>
<p><code>Peter<br />
Thomas<br />
Stefan</code></p>
<p>We can also create a new object for a specific Task</p>
<p><code>[Object]$xmltask2 = $xmldata.TodoList.Task | Where-Object {$_.ID -eq "2"}</code></p>
<p>Now we have a new object with data from Task ID 2. If we wanna see the name from this we just use the same command with the new object</p>
<p><code>$xmltask3 | <strong>%</strong>{$_.Name}</code></p>
<p><code>Thomas</code></p>
<p>We can do a lot more with this, but I will bring this up in the next blog posts.</p>
<div class="shr-publisher-724"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2010/06/powershell-parsing-xml-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Powershell: Invoke-Expression</title>
		<link>http://www.thomasmaurer.ch/2010/05/powershell-invoke-expression/</link>
		<comments>http://www.thomasmaurer.ch/2010/05/powershell-invoke-expression/#comments</comments>
		<pubDate>Sun, 30 May 2010 11:11:08 +0000</pubDate>
		<dc:creator>Thomas Maurer</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Cmdlet]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[Expression]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Invoke]]></category>
		<category><![CDATA[Microsoft Powershell]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Powershell Script]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Variables Invoke-Expression]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Powershell]]></category>

		<guid isPermaLink="false">http://www.thomasmaurer.ch/?p=620</guid>
		<description><![CDATA[Using the Invoke-Expression Cmdlet: The Invoke-Expression cmdlet provides one way to run a script from within Windows PowerShell. Invoke-Expression c:\scripts\test.ps1 or &#38; c:\scripts\test.ps1 And you also can run a function in your Powershell Script by a variable. This is something really &#8230; <a href="http://www.thomasmaurer.ch/2010/05/powershell-invoke-expression/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img class="alignnone size-full wp-image-621" title="Powershell Header" src="http://www.thomasmaurer.ch/wp-content/uploads/2010/05/Screen-shot-2010-05-30-at-13.08.42.png" alt="Powershell Header" width="440" height="104" /></p>
<p>Using the Invoke-Expression Cmdlet:</p>
<p>The <strong>Invoke-Expression</strong> cmdlet provides one way to run a script from within Windows PowerShell.</p>
<p><code>Invoke-Expression c:\scripts\test.ps1</code></p>
<p>or</p>
<p><code>&amp; c:\scripts\test.ps1</code></p>
<p>And you also can run a function in your Powershell Script by a variable. This is something really important when you work with dynamic scripts:</p>
<p><code>Invoke-Expression -command ($Function_Name)</code></p>
<p>you even can send dynamic parameters to this function:</p>
<p><code>Invoke-Expression -command ($Function_Name + ' $Function_Parameters')</code></p>
<div class="shr-publisher-620"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thomasmaurer.ch/2010/05/powershell-invoke-expression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

