Monday, March 31, 2008

Free EBook - Windows Server PowerShell Scripting Step by Step


imageTeach yourself the fundamentals of Windows PowerShell command line interface and scripting language. Written by a leading scripting expert, this tutorial delivers self-paced labs, timesaving tips, and hands-on sample scripts for automating Windows administration—one step at a time.



Discover how to:

•Use built-in cmdlets to execute commands
•Write scripts to handle recurring tasks and configure scheduled jobs
•Use providers to access information external to the shell environment
•Configure network components using Windows Management Instrumentation (WMI)
•Manage users, groups, and computers with Active Directory Services
•Execute scripts for administering and troubleshooting Microsoft Exchange Server 2007
•PLUS—Get a complete list of cmdlet commands and a guide for moving from VBScript to Windows Powershell


Register and Download

Free EBook - Introducing Windows Server 2008



Get a jump on evaluating Window Server 2008 - with technical insights from Windows Server team. This practical introduction delivers real-world implementation scenarios and pragmatic advice for administering Windows Server in the enterprise.



About the book:

•Deploy Windows Server 2008, and configure and manage server roles
•Understand Windows Server Virtualization
•Implement a single, integrated IDA solution built on Active Directory
•Explore enhancements in Internet Information Services 7.0
•Use failover clustering for high-availability solutions
•Implement the Network Access Protection platform


Register and Download

Friday, March 28, 2008

NetCmdlets V2.0 - BETA


/n software NetCmdlets extend the features of Microsoft Windows PowerShell with a broad range of network management and messaging capabilities. The current release contains more than 30 Cmdlets providing access to network and host protocols such as SNMP, LDAP, DNS, Syslog, HTTP, WebDav, FTP, SMTP, POP, IMAP, Rexec/RShell, Telnet, and more.

Using Windows PowerShell and NetCmdlets, System Administrators can easily script common network management tasks including router configuration, switch port monitoring, directory access, VLAN administration, remote execution, etc.

NetCmdlets V2 is packed full of exciting new features including PowerShell Server (formerly PowerShell Remoting), Parameter Sets, Object Pipelining, and new Cmdlets for SSH Enabled Remoting and Amazon Web Services (S3) Integration.

Check out the new features in this release or download the beta!

Sunday, March 23, 2008

Windows Server Core - CoreConfigurator to the rescue


If you need to configure Server Core to get your installation up and running but you're not
a command-line expert then check CoreConfigurator.

Guy Teverovsky, Windows Server MVP, comes to rescue with a simple GUI utility to do all the
hard work for you.


CoreConfigurator Features:

  • Product Activation
  • Configuration of display resolution
  • Clock and time zone configuration
  • Remote Desktop configuration
  • Management of local user accounts (creation, deletion, group membership, passwords)
  • Firewall configuration
  • WinRM configuration
  • IP configuration
  • Computer name and domain/workgroup membership
  • Installation of Server Core features/roles


Here's a screenshot of the main screen:


Thursday, March 20, 2008

Create Certificate for Exchange 2007 Servers using Windows CA


Ronen Gabbay [MVP], Microsoft Exchange Regional Director (and my Exchange 2007 course instructor), shows how you can create Certificate for Exchange 2007 Servers using Windows CA for SSL, OWA and SMTP use.

Wednesday, March 19, 2008

2008 Scripting games prizes


I got an email from Greg Stemp, the Scripting Guy. He notified me that I won a licensed copy of ShellTools' PowerShell Analyzer/PowerShell Plus and a PowerShell T-shirt. I'm also eligible for a Scripting Games Certificate of Excellence. WOW, Thank you!

Monday, March 17, 2008

TechNet Webcsat: 24 Hours of Windows Server 2008


Prepare yourself for the next release of Microsoft’s server operating system - Windows Server 2008. Tune in and learn how you can leverage the new features to improve your organization's networking infrastructure and security, server performance and reliability, remote resource access, and client deployment. Subject matter experts break down what these upgrades mean for your environment and how to take advantage of them.

There is also an interactive Webcast Calendar where you can quickly find live webcasts that fit your schedule as well as on-demand webcasts to view at your convenience. You can choose your time zone and filter the list by audience, webcast series, product or topic, and Presenter.



On-Demand Webcasts

24 Hours of Windows Server 2008 (Part 01 of 24): Overview (Level 200)

24 Hours of Windows Server 2008 (Part 02 of 24): Server Virtualization with Hyper-V Features and Architecture (Level 200)

24 Hours of Windows Server 2008 (Part 03 of 24): Managing Hyper-V (Level 200)



Live Webcasts

24 Hours of Windows Server 2008 (Part 04 of 24): Presentation Virtualization with Terminal Services RemoteApp (Level 200)

Friday, March 14, 2008
9:30 A.M.–11:00 A.M. Pacific Time


24 Hours of Windows Server 2008 (Part 05 of 24): Terminal Services Gateway and Terminal Services Web Access (Level 200)

Wednesday, March 19, 2008
9:30 A.M.–11:00 A.M. Pacific Time


24 Hours of Windows Server 2008 (Part 06 of 24): Deploying and Migrating to Terminal Server (Level 200)

Friday, March 21, 2008
9:30 A.M.–11:00 A.M. Pacific Time


24 Hours of Windows Server 2008 (Part 07 of 24): IIS 7.0 Overview and Architecture (Level 200)

Wednesday, March 26, 2008
9:30 A.M.–11:00 A.M. Pacific Time


24 Hours of Windows Server 2008 (Part 08 of 24): IIS 7.0 Advanced Management (Level 200)

Friday, March 28, 2008
9:30 A.M.–11:00 A.M. Pacific Time

Culture dependent date formatting


This week's Windows PowerShell Tip of the Week was on Creating a Graphical Date Picker. It shows an excellent way to overcome the difficulty of controlling the user's date-format when entering a date at the command prompt.

Anyway, It was intriguing and I found myself venturing into dates and cultures. I wanted to see how DateTime values are formatted and displayed, depending on the culture (specifically the ShortTimePattern).

The CultureInfo class provides information about a specific culture. The information includes the names for the culture, the writing system, the calendar used, and formatting for dates and sort strings. 

To get the above information for a specific Culture/Language Name you can pass the culture name to the cultureInfo constructor. The DateTimeFormat member shows all the members involved when a date is formatted.


$ci = new-object system.globalization.cultureInfo "en-US"

AMDesignator                     : AM
Calendar                         : System.Globalization.GregorianCalendar
DateSeparator                    : /
FirstDayOfWeek                   : Sunday
CalendarWeekRule                 : FirstDay
FullDateTimePattern              : dddd, MMMM dd, yyyy h:mm:ss tt
LongDatePattern                  : dddd, MMMM dd, yyyy
LongTimePattern                  : h:mm:ss tt
MonthDayPattern                  : MMMM dd
PMDesignator                     : PM
RFC1123Pattern                   : ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
ShortDatePattern                 : M/d/yyyy
ShortTimePattern                 : h:mm tt
SortableDateTimePattern          : yyyy'-'MM'-'dd'T'HH':'mm':'ss
TimeSeparator                    : :
UniversalSortableDateTimePattern : yyyy'-'MM'-'dd HH':'mm':'ss'Z'
YearMonthPattern                 : MMMM, yyyy
AbbreviatedDayNames              : {Sun, Mon, Tue, Wed...}
ShortestDayNames                 : {Su, Mo, Tu, We...}
DayNames                         : {Sunday, Monday, Tuesday, Wednesday...}
AbbreviatedMonthNames            : {Jan, Feb, Mar, Apr...}
MonthNames                       : {January, February, March, April...}
IsReadOnly                       : False
NativeCalendarName               : Gregorian Calendar
AbbreviatedMonthGenitiveNames    : {Jan, Feb, Mar, Apr...}
MonthGenitiveNames               : {January, February, March, April...}


Based on the above it is very easy to construct a table that gets all cultures and format each culture date according to its ShortTimePattern pattern. Note that some cultures do not have ShortTimePattern hence the where clause:

$date = @{n="Date";e={Get-Date -f $_.DateTimeFormat.ShortDatePattern}}
$sdp = @{n="Pattern";e={$_.DateTimeFormat.ShortDatePattern}}
$cultures = [System.Globalization.CultureInfo]::GetCultures("AllCultures")
$cultures | where {$_.DateTimeFormat.ShortDatePattern} | select LCID,Name,DisplayName,$date,$sdp | ft -a



Note the first culture in the sample output. An Invariant culture is culture-insensitive (independent). Your application specifies the invariant culture by name using an empty string ("") or by its identifier. InvariantCulture defines an instance of the invariant culture. It is associated with the English language but not with any country/region. It is used in almost any method in the Globalization namespace that requires a culture.




There is also the DateTimeFormatInfo Class. This class contains information, such as date patterns, time patterns, and AM/PM designators. It also offers a comprehensive list of custom DateTime format patterns and their behavior which you can use when formatting dates with Get-Date or with the ToString() method.

Thursday, March 13, 2008

No-Tech Hacking

Johnny (I hack stuff), a security researcher and author of numerous computer security books  (Google Hacking) gives a super amazing (funny) lecture on "No-Tech Hacking" - Bypassing high-tech security without the use of technology.


Webcast: Using VMM and PowerShell to Deploy HP Windows Server 2008 Academy Labs


You can download the webcast recordings for offline view (14MB).


Event Overview

We have deployed 660 virtual machines for the student labs that are a key part of the week-long Academy. Provisioning and lab setup was administered using Microsoft System Center Virtual Machine Manager 2007 and Window PowerShell. This fast-paced webcast summarizes the IT professional experience of using a Windows PowerShell script and Virtual Machine Manager to automate the deployment of virtual machines (VMs). We review the HP academy, introduce Virtual Machine Manager and its features, walk though how the VMs were deployed via the scripted process, and discuss the benefits of using Virtual Machine Manager and Windows PowerShell to manage the VMs once they have been deployed. We also give you tips for using the Virtual Machine Manager Windows PowerShell cmdlets! Attend this presentation to gain the confidence to start automating the administrating virtual environments using Virtual Machine Manager and Windows PowerShell.

Monday, March 10, 2008

Custom PowerShell prompt


If you are used to measuring commands in PowerShell then this custom prompt can be useful for you. Instead of measuring commands manually (with measure-command), the custom prompt code (below, comments inline) automates the measuring process and presents three bits of information at the console title. Here is how it looks:



  1. The first part (c:\scripts) shows the current working directory.
  2. The second part (Session Execution Time: 00:12:15) displays, in HH:mm:ss format, the total amount of time it took PowerShell to execute all commands since the console had started.
  3. The last part (Last [00:01.546]) displays how long it took the last command to be completed, in mm:ss.millisecond format.

The last part of the prompt (PS 3>) shows the ID of the last executed command, you ca use the ID to invoke commands, instead of retyping them, from the commands history by passing the command ID, see the help for get-history.

To use the prompt, copy the code below and paste it into your $profile, restart PowerShell and type some commands, you'll see the console title changes.


***UPDATE # 1 ***
Already found a bug. Repeatedly pressing the ENTER key causes the global $pshUse to add-up the last command execution time. The code below includes the fix.

***UPDATE # 2 ***

Added support for $NestedPromptLevel visualization. Thanks Andy!
Each nested prompt level is indicated by an extra ">"


# global variable to hold total (cumulative) execution time
$global:pshUse = New-TimeSpan
# holds the last command id
function Prompt{ 
    # get the last command
    $item = Get-History -Count 1
    # don't add-up times when typing ENTER repeatedly
    if($global:lasdID -ne ${
        # get the last command execution time (timespan)
        $diff = $item.EndExecutionTime-$item.StartExecutionTime
        # add it to the global $pshUse
        $global:pshUse = $global:pshUse.Add($diff)
        # string format total execution time in HH:mm:ss 
        # and last command execution time in mm:ss.milliseconds    
        $title = "{0:T} , Last [{1:mm:ss.fff}]" -f [datetime]($pshUse.ticks),[datetime]($diff.ticks)
        # update console title, show current directory, 
        # session execution time, and last command execution time
        $host.UI.RawUI.WindowTitle = "{0} | Session Execution Time: {1}" -f $pwd,$title
    # write custom prompt with the last history command id 
    # each nested prompt level is indicated by an extra ">" 
    "PS {0}{1} " -f $, (">"*($NestedPromptLevel+1))



Wednesday, March 5, 2008

The Third Annual Scripting Games


The Third Annual Scripting Games is over. This year's event was full of challenges for everyone, beginners and veteran scripters alike, and included a third (non-Microsoft) scripting language for submitting solutions - Perl.

I've managed to get a perfect score in both Sudden Death Challenge and Advanced PowerShell divisions.

I would also like to congratulate the Scripting Guys for a well designed and well organized event. This year's event was much harder and more challenging than previous years. I'm curious to see what they have up their sleeve for next year's event, can't wait!

By the way, until the 2009 games, if you're looking for a 24x7 real world PowerShell challenge - I know the right place... Join the newsgroup and sharpen your PowerShell skills and knowledge.

2008 Scripting Games - Advanced Event 9

Event 9: You’re Twisting My Words


$content = [System.IO.File]::ReadAllText("C:\Scripts\alice.txt")
$reversed = $content.split() | foreach {"$($_[($_.length-1)..0])" -replace " " }
[string]::Join(" ",$reversed)

resuoiruC' dna '!resuoiruc deirc ecilA ehs( saw os hcum ,desirprus taht rof eht tnemom ehs etiuq togrof woh ot kaeps doog ;)hsilgnE won' m'I gninepo tuo ekil eht tsegral epocselet taht reve !saw ,eyb-dooG '!teef rof( nehw ehs dekool nwod ta reh ,teef yeht demees ot eb tsomla tuo fo ,thgis yeht erew gnitteg os raf .)ffo ,hO' ym roop elttil ,teef I rednow ohw lliw tup no ruoy seohs dna sgnikcots rof uoy ,won ?sraed m'I erus _I_ t'nahs eb !elba I llahs eb a taerg lae
d oot raf ffo ot elbuort flesym tuoba :uoy uoy tsum eganam eht tseb yaw uoy ;nac tub-- I tsum eb dnik ot ',meht thguoht ,ecilA ro' spahrep yeht t'now klaw eht yaw I tnaw ot !og teL em :ees ll'I evig meht a wen riap fo stoob yreve '.samtsirhC

2008 Scripting Games - Advanced Event 10

Event 10: Blackjack!


$cards = "ah", "ac", "ad", "as",
       "2h", "2c", "2d", "2s",
       "3h", "3c", "3d", "3s",
       "4h", "4c", "4d", "4s",
       "5h", "5c", "5d", "5s",
       "6h", "6c", "6d", "6s",
       "7h", "7c", "7d", "7s",
       "8h", "8c", "8d", "8s",
       "9h", "9c", "9d", "9s",
       "th", "tc", "td", "ts",
       "jh", "jc", "jd", "js",
       "qh", "qc", "qd", "qs",
       "kh", "kc", "kd", "ks"

function resolve-cardSign([string]$str){
        "d" {"Diamonds"; break}
        "c" {"Clubs"; break}
        "s" {"Spades"; break}
        "h" {"Hearts"; break}

function resolve-cardName([string]$str){
        "a" {"Ace"; break}
        "2" {"Two"; break}
        "3" {"Three"; break}
        "4" {"Four"; break}
        "5" {"Five"; break}
        "6" {"Six"; break}
        "7" {"Seven"; break}
        "8" {"Eight"; break}
        "9" {"Nine"; break}
        "t" {"Ten"; break}        
        "j" {"Jack"; break}
        "q" {"Queen"; break}
        "k" {"King"; break}    

function resolve-cardValue([string]$str){
        "a" {11; break}
        {$_ -match "[tjqk]"} {10; break}
        default {$_}

function shuffle-deck{
    for ($i = 0; $i -le $max;$i++) {
        $r = $$max)
        $deck[$i],$deck[$r] = $script:deck[$r],$script:deck[$i]

function deal-user($num){
    1..$num | foreach {
        $r = $$deck.count)
        $cardName = "{0} of {1}" -f (resolve-cardName $deck[$r]),(resolve-cardSign $deck[$r])
        $script:user+= resolve-cardValue $deck[$r]

function deal-dealer($num){
    1..$num | foreach {
        $r = $$deck.count)
        $cardName = "{0} of {1}" -f (resolve-cardName $deck[$r]),(resolve-cardSign $deck[$r])
        $script:posh+= resolve-cardValue $deck[$r]

function print-hands([switch]$reveal){
    "`nYour cards:"
    "`nDealer's cards:"
    } else {

$rnd = New-Object System.Random (get-date).millisecond

$deck = new-object system.collections.arraylist
$cards | foreach { [void]$deck.add($_) }

deal-user 2
deal-dealer 2
$host.ui.RawUI.WindowTitle = "user: $user, posh $posh"
# while user score are less then 21 and user wants another card
while(($user -lt 21) -and ((read-host "Stay (s) or hit (h) ?") -eq "h")){
    deal-user 1
    $host.ui.RawUI.WindowTitle = "user: $user, posh $posh"
    "`nYou have $user`n"

    if($user -eq 21) {print-hands -reveal; "You win."; return}
    if($user -gt 21) {
        print-hands -reveal
        "`nOver 21. Sorry, you lose."

    if(($user -eq 21) -and ($posh -eq 21)) {
        print-hands -reveal
        "`nYou have $user,`nThe dealer has $posh. Ties (pushes) go the dealer. Sorry, you lose."
    #$script:userCards; "You win."; return


"You have $user`n"

# if dealer's hand is greather than users hand then the dealer wins
if(($posh -gt $user) -and ($posh -le 21)) {
    print-hands -reveal
    "`nYou have $user.`nThe dealer has $posh. Sorry, you lose."; return

while($posh -lt $user) {deal-dealer 1}

# final results
if($posh -eq $user) {
    "`nYou have $user,`nThe dealer has $posh. Ties (pushes) go the dealer. Sorry, you lose."

print-hands -reveal
if(($posh -gt $user) -and ($posh -le 21)){
    "`nThe dealer has $posh. You have $user, You lose."
} else {
    "`nThe dealer has $posh. You have $user, You win."

Monday, March 3, 2008

The Middle Bronze Age scripting games challenge


Despite a century of study, researchers can agree on the decipherment of only a single phrase of Proto-Sinaitic script, a Middle Bronze Age alphabet dating to 1500 BCE. The Proto-Sinaitic script is one of two similar undeciphered scripts dated to that period and believed to be ancestral to nearly all modern alphabets. Many experts believe the language of Proto-Sinaitic inscriptions is Semitic, and cite the one phrase that was interpreted as proof of this hypothesis. What is the phrase?

Find the answer here.

Saturday, March 1, 2008

Sudden Death Challenge: Event 9


(cat C:\Scripts\symbols.txt) -replace '[^a-zA-Z0-9 ]'

# result

The 2008 Winter Scripting Games