Search
Twitter
Subscribe

Entries in PowerShell (2)

Monday
Aug132012

Convert-WindowsImage.ps1 -ShowUI

I have used WIM2VHD.wsf in the past, and now that I'm spending more time in Hyper-V (both in Windows 8 Release Preview, and in Server 2012 Release Candidate), this Convert-WindowsImage.ps1 PowerShell script provides a nicely improved workflow for quickly creating new VHD (or VHDX) files.

Here's an example of how you can use it in a GUI mode. In this example, I pointed the source to the Windows Server 2012 RC ISO that I downloaded, and created a new dynamic 40GB VHDX from the Standard edition within that ISO.

PS E:\scripts> .\Convert-WindowsImage.ps1 -ShowUI

Note: the current directory where the script is launched from will be the path where the new VHD or VHDX will be created.

Windows(R) Image to Virtual Hard Disk Converter for Windows(R) 8
Copyright (C) Microsoft Corporation.  All rights reserved.
Version 6.2.8424.0.amd64fre.fbl_core1_hyp_dev(mikekol).120517-1616 Release Preview
INFO   : Launching UI...

 

INFO   : Opening ISO 8400.0.WINMAIN_WIN8RC.120518-1423_X64FRE_SERVER_EN-US-HRC_SSS_X64FRE_EN-US_DV5.ISO...
INFO   : Looking for H:\sources\install.wim...
INFO   : Scanning WIM metadata...
INFO   : Selected Working Directory is E:\Virtual Machines\Hyper-V Disks...
INFO   : Image 2 selected (ServerStandard)...
INFO   : Creating sparse disk...
INFO   : Attaching VHDX...
INFO   : Disk initialized...
INFO   : Disk partitioned...
INFO   : Volume formatted...
INFO   : Access path (I:\) has been assigned...
INFO   : Applying image to VHDX.  This could take a while...
INFO   : Signing disk...
INFO   : Image applied.  Making image bootable...
INFO   : Opening I:\boot\bcd for configuration...
INFO   : BCD configuration complete. Moving on...
INFO   : Drive is bootable.  Cleaning up...
INFO   : Closing VHDX...
INFO   : Closing Windows image...
INFO   : Done.

 

And now I have a new "Server2012RCstd.vhdx" that I can attach to a new virtual machine and boot!

 

Friday
May212010

New PowerShell scripts to share

I had a recent project where I needed to brush up on PowerShell, and I didn't find any other scripts shared online for my specific issue, so I thought I'd share what I came up with.

It's not particularly complex, but hopefully someone will find it helpful.

 

I put GetDataSet.ps1 together because I needed to be able get SQL records from an ODBC data source. I had read the System Center Central post on connecting to SQL with PowerShell, but it seemed like PowerShell has some built-in Microsoft SQL Server support that didn't apply to other data sources. I found a basic template PowerShell script for ADODB (ActiveX Database Objects) on the Hey, Scripting Guy! blog at TechNet. I had to customize the connection string for my specific ODBC driver, and I tried to leave this shared version of the script generic and commented so that you can tweak it for your own situation.

 

Another PowerShell script I use fairly regularly is checkProcess.ps1. It started as a basic kill process script, then I added the ability to more gracefully close down certain applications. After a while I realized I was also periodically starting some of these same apps, so I updated the script to be able to start them as well. One of the latest enhancements I owe to another System Center Central post, by Tenchuu, clarifying how the PowerShell count property behavior can change based on context. If nothing else, working on this script gave me excuses to work on nuance in PowerShell like checking arguments, write-progress, and declaring data types.

If you try out either of these scripts, let me know what you think by adding feedback to this post or using the Contact page.