Monthly Archive


Monthly Archives: April 2013

PowerShell Summit–thank you

I’d like to extend a huge thank you to everyone who attended the PowerShell Summit this last week.  The Summit was a success – in no small part due to you. Your questions, and discussions, are what this is all about.

It was a pleasure meeting you all and I hope to return next year – I hope to see many of you there as well.

PowerShell Deep Dives–another MEAP release


Manning have released another set of chapters in their early access program for PowerShell Deep Dives.

If you have an interest in PowerShell I would strongly urge you to buy a copy. It has chapters from a number of well known PowerShell authors together with some very good material from new authors.  Best of all the royalties are going to charity.

Busy, busy, busy

A very busy time coming up in PowerShell land with the first PowerShell Summit kicking off in just over a week’s time.  The 2013 Scripting Games will also be starting very soon.

I’ll try and post about both of them as time allows

Creating a new disk

I really like Windows Server Core. The concept has come of age in Windows 2012.

I needed to add a new disk to a virtual machine  - that’s easy using the Hyper-V cmdlets. But what about formating the disk.

A module new to Windows 2012 & Windows can be used.  Its the Storage module.  I’ve not had chance, or reason, to play with this module yet. So many cmdlets so little time.

Start with viewing the disks:

PS C:\Users\richard> Get-Disk | ft -a

Number Friendly Name          OperationalStatus Total Size Partition Style
------ -------------          ----------------- ---------- ---------------
0      Virtual HD ATA Device  Online                120 GB MBR
1      Microsoft Virtual Disk Offline               127 GB RAW


Disk 1 is the new disk so need to initialise it.

PS C:\Users\richard> Initialize-Disk -Number 1 -PartitionStyle MBR

View the disks again

PS C:\Users\richard> Get-Disk | ft -a

Number Friendly Name          OperationalStatus Total Size Partition Style
------ -------------          ----------------- ---------- ---------------
0      Virtual HD ATA Device  Online                120 GB MBR
1      Microsoft Virtual Disk Online                127 GB MBR


Create a partition on the disk -   -useMaximimSize means use all of the disk for this partition

PS C:\Users\richard> New-Partition -DiskNumber 1 -UseMaximumSize -DriveLetter R

Now view the partitions

PS C:\Users\richard> Get-Partition | ft -a

   Disk Number: 0

PartitionNumber DriveLetter Offset         Size Type
--------------- ----------- ------         ---- ----
1                           1048576      350 MB IFS
2               C           368050176 119.66 GB IFS

   Disk Number: 1

PartitionNumber DriveLetter Offset    Size Type
--------------- ----------- ------    ---- ----
1               R           1048576 127 GB Logical

And finally format the new disk:

PS C:\Users\richard> Get-Volume | where DriveLetter -eq R | Format-Volume -FileSystem NTFS -NewFileSystemLabel Backup

Are you sure you want to perform this action?
Warning, all data on the volume will be lost!
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

You get a nice friendly warning (you could bypass using –Confirm $false) and the format happens

You could pipe the cmdlets together to do everything in one pass. Best of all – the cmdlets are WMI based.

Windows Server Backup

Windows Server 2012 has a PowerShell enabled backup utility. When you enable the feature you get a module called WindowsServerBackup.  It has the cmldets you would expect for creating and managing backups. No surprise you may say as this was avialable in Windows 2008 R2.

The difference with Windows Server 2012 is that you can do restores from PowerShell cmdlets whcih wasn’t available in the earlier version.

The restore cmdlets are






This might not replace your currebt backup system but is very useful for backing up test environments and experimenting with things like authorative AD restores.

Running workflows

I tripped over an interesting issue recently regarding the running of PowerShell workflows.

Consider the world’s simplest workflow

workflow test-w1 {"hello world"}

If I run this on a 32bit Windows 8  PowerShell machine – it works

If I run this on Windows 2012 (64bit) on PowerShell it works

if I run this on Windows 2012 PowerShell (x86) – it doesn’t work!

Be aware of how you are running your workflows

AD Management in a Month of Lunches

The MEAP marches on with chapter 8 now released:

Chapter 8 – creating Group Policies

details from

Manning Deal of the Day – April 6 2013

My PowerShell and WMI book will be Manning’s deal of the day for 6 April 2013.  The deal will go live at Midnight US ET and will stay active for about 48 hours.

This is your chance to get the book with a 50% discount.

Use code dotd0406au at

The Deal of the Day offer also applies to SharePoint Workflow in Action (


Putting the date in a file name

I often need to create file names that include the date & time the file was created in the name. I’ve come up with all sorts of ways to do but this I think is the simplest.

I want the date in this format:  year-month-day-hour-minute-second.  In other words a format that is easily sortable. I discovered that if you convert a data to a string there is a formatter that does most of the work for you.  That’s a lower case s.

PS> (Get-Date).ToString("s")

You can’t have a : symbol in a file name so need to get rid of those

PS> (Get-Date).ToString("s").Replace(":","-")

To complete the file name

PS> $datestring = (Get-Date).ToString("s").Replace(":","-")
PS> $file = "c:\folder\Prefix_$datestring.txt"
PS> $file

I’ve done this as a two step process otherwise when you replace the : you also take out the one for the disk drive – oops


PowerShell excerpt week

The Scripting Guy is running a series of excerpts from the PowerShell books published by Manning.  Today is PowerShell in Practice

Check out the deals all this week on Manning PowerShell books