Powershell: Count Sharepoint Sites on Sharepoint Server 2010

Powershell Header

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.

iOS 4.1 beta 2 with calendar invites

Apple just released iOS 4.1 beta 2. After some testing I found something I was looking for in every release. In iOS 4.1 beta 2 you can now send calendar invites to other people by creating a new event.

Powershell: Working with XML part 2

Powershell Header

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 file and save the XML objects as a file.

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.

I created a little retry part (Powershell: Simple retry logic) 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.

Thats the story behind my idea for saving data in a XML file.

Creating a XML object

[XML]$FruitList = "<Box>
<Fruit>
<Name>Banana</Name>
<Color>yellow</Color>
</Fruit>
</Box>"

Save a XML object as a XML file

$FruitList.Save("./myfruitlist.xml")

XML:

<Box>
	<Fruit>
		<Name>Banana</Name>
		<Color>yellow</Color>
	</Fruit>
</Box>

Open a saved XML file

[xml]$FruitList = Get-Content ./myfruitlist.xml

Add data to XML object and save it in a XML file

# 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")

XML:

<Box>
	<Fruit>
		<Name>Banana</Name>
		<Color>yellow</Color>
	</Fruit>
	<Fruit>
		<Name>Apple</Name>
		<Color>green</Color>
	</Fruit>
</Box>

Change data from XML Object and save it as XML file

# 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")

XML:

<Box>
	<Fruit>
		<Name>Banana</Name>
		<Color>yellow</Color>
	</Fruit>
	<Fruit>
		<Name>Apple</Name>
		<Color>red</Color>
	</Fruit>
</Box>

Remove data from XML Object and save it as XML file

# 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")

XML:

<Box>
	<Fruit>
		<Name>Apple</Name>
		<Color>green</Color>
	</Fruit>
</Box>

Powershell: Count your Code lines

Powershell Header

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 (Get-Content) and count the lines in there.

The other way and the fasterway is with Select-String:

(Get-ChildItem -Include *.ps1 -Recurse | Select-String -pattern .).Count

HP iLO3: What’s new

HP iLO3

With the new G7 Serverline, HP released also iLO 3 (HP Integrated Lights-Out). With new and important features:

  • 800% faster remote console: best-in-class remote management performance
  • 360% faster Virtual Media: higher performance remote deployment and updates
  • Improved Windows Integrated Remote Console: .NET framework, so you can scale your remote console to fit your screen and even stretch across multiple monitors
  • Linux Integrated Remote Console: Linux IRC incorporates remote console, virtual media, and virtual power, so you can handle these tasks with one applet
  • AES Encryption in hardware: industrial-strength security with no performance penalty
  • Enhanced IPMI LAN Support: simple server control in scale-out environments
  • iLO Advanced is already included with the purchase of HP Insight Control for Complete lifecycle management for your ProLiant server and can also be purchased stand alone.