PowerShell for Windows Admins


March 4, 2010  2:35 PM

What’s the time

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

I was answering a question about time synchronisation and it got me wondering about check the time on multiple machines.

001
002
003
004
005
006
007
008
009
010
011
012
$computer = "." 
Get-WmiObject -Class Win32_LocalTime -ComputerName $computer | foreach {
    "Local Time"
    Get-Date -Day $_.Day -Month $_.Month -Year $_.Year `
      -Hour $_.Hour -Minute $_.Minute -Second $_.Second
}

Get-WmiObject -Class Win32_UTCTime -ComputerName $computer | foreach {
    "UTC Time"
    Get-Date -Day $_.Day -Month $_.Month -Year $_.Year `
      -Hour $_.Hour -Minute $_.Minute -Second $_.Second
}

 

We can use a simple bit of WMI to check both the Local time and UTC time if we span multiple time zones.  if you need to check many machines put the code in a function and pass the computer names from a  csv file

Technorati Tags:

March 4, 2010  1:41 PM

Manning Special Offer

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Manning – the publishers of my book – have a big promotion on Friday 5 March.

Go to www.manning.com on Friday and get 50% off any MEAP.

 

MEAP is Manning Early Access Program – get early access to the book (raw manuscript) and get the full book delivered when its published.

Good time to stock on the PowerShell book you’ve always wanted (especially as it will be out of MEAP soon)  :-)

Technorati Tags: ,


March 1, 2010  1:19 PM

Practical Virtualization Solutions

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Authors: Kenneth Hess and Amy Newman

Publisher: Prentice Hall

ISBN: 978-013-714297-2

 

Subtitled Virtualization from the Trenches the book sets out to be “The 100% Practical Guide to Making Virtualization Work in Enterprise Environments”. I tend to judge a book on a number of points:

  • Is it technically accurate?
  • Does deliver the material it claims to deliver?
  • Is worth the cost of purchase and the time I spend reading it?

We’ll see how this stacks up at the end of the review.

At 290 pages Practical Virtualization Solutions is divided into a number of parts:

  • 1. Virtualization Basics and Technology Choices
  • 2. Applying Virtualization
  • 3. Building the Virtual Infrastructure: Hardware’s Role in Virtualization
  • 4. From Development to Production: Managing the Virtual Infrastructure

Part 1 consists of 8 chapters.  The first chapter covers the question “Why virtualise?” It supplies a good coverage of this question though the section on minimising hardware costs is not particularly clear. Chapter 2 looks at the types of virtualisation that are available including hypervisors, emulation and shared kernel.

The next 6 chapters each give an overview of a virtualisation platforms, namely: VMware server, VMware ESXi, Citrix XenServer, Microsoft Virtual PC, Microsoft Hyper-V and Sun VirtualBox. Some of the choices seemed a bit surprising especially Virtual PC and VirtualBox. Virtual PC is a platform for running a couple of Virtual Machines on your desktop computer it’s not an enterprise virtualisation platform. It does not, as claimed, support 64bit hosts.

Equally surprising was the exclusion of the Novell virtualisation solution especially given the relationship, and mutual support, agreed between Microsoft and Novell. The chapter on Hyper-V is also disappointing in that the version under review appears to be that in Windows Server 2008 rather than Windows Server 2008 R2. The R2 version is a significant upgrade and would have been available during the writing of the book.

The rest of the book uses VMware as examples which is fair enough if that is the platform with which the authors have most experience . However, it does give the impression that the authors think VMware is the correct platform for enterprise level server virtualisation.

Part 2 starts with chapter 9, which covers configuring and tuning the virtualisation hosts as well as physical to virtual migrations. Chapter 10 covers desktop virtualisation including Terminal Services, hosted desktop (VDI), web based solutions and CD or USB drive based solutions. While recommending against VDI type solutions the chapter fails to mention some of the benefits around licensing and the fact that provisioning servers can drastically reduce the number of images needed. What was missing from this chapter was a discussion of application virtualisation using products such as Microsoft’s App-V (Softgrid) that offer a way to virtualise the presentation of applications for mobile and static workers.

Chapter 11 on Network and Storage Virtualisation is a bit mixed. The storage virtualisation section I found interesting and informative as I didn’t know much about this area. The network section spends a lot of time discussing VPNs and VLANs which seemed at a tangent to the rest of the book.

Part 3 discusses hardware. Chapter 12 discusses form factor and sets out the pros and cons of rack mounted servers and blades. I’m not a big fan of blades as I think they bring in an un-needed level of complication but the discussion was fair. Chapter 13 on choosing a Vendor seemed a waste. Many organizations have a preferred vendor, or buy from however has the best deal available. I agree with the comment about buying quality hardware but it doesn’t need a chapter to make it. Chapter 13 covers network virtualisation and storage virtualisation again – properly this time. This is a very useful and informative chapter.

Part 4 covers the virtualisation project with the usual stages of planning (chapter 15), deployment (chapter 16) and post implementation (chapter 17). One piece missing from the section discussing management of the virtual environment is Microsoft’s System Center Virtual Machine Manager which can manage Hyper-V, Virtual Server, Novell and will manage VMware in the future. Other products are making similar expansions to cover multiple platforms.

The book assumes a single virtualisation platform for the enterprise but in reality many, if not most, organisations will have a heterogeneous environment with multiple platforms. A section discussing the implications of this would have been useful.

I said at the beginning I have three criteria:

  • Is it technically accurate?
  • Does deliver the material it claims to deliver?
  • Is worth the cost of purchase and the time I spend reading it?

How does the book stack up against them?

For technical accuracy I would give 8/10. There are a number of small inaccuracies but nothing leaped out as being a major error. The technical coverage I thought was a bit patchy with some products, presumably the ones the authors are most familiar with, getting more attention.

The claim to be a 100% practical guide to making virtualisation work I don’t think is met. This book by itself is not sufficient to guide a virtualisation project in an organisation of any size. However, I think it is a superb introduction to virtualisation for any one new to the subject.  Overall, I would give the book 7/10 on this criterion.

The final judgement is on cost and time to read being worthwhile. At £28.99 ($39.99) full price it is quite expensive for a book that barely manages 300 pages including the index. The on line book shops bring the price down to a more realistic figure.  Was it worthwhile reading? Yes. I’ve been around virtualisation projects for a while but still managed to learn some things from it. Trying to judge the book from a virtualisation newcomer’s perspective I’d probably give it 8/10.

Overall, I’d give the book 8/10 and think of it as a good introduction to the subject but definitely not the last word.


February 24, 2010  1:12 PM

Windows PowerShell Community Review

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

Have you ever read Help that wasn’t really helpful? Here’s your chance to fix it.

The Windows PowerShell documentation team and PowerShellCommunity.org jointly sponsor the Windows PowerShell Community Doc Review. As a member, you’ll get to read and comment on the Help docs before they’re published, and work with the writers, editors, and the product team to make sure every word is really helpful.

We’re looking for users at all experience levels and with all different backgrounds, but we love to have beginners, people with no programming experience, people who know other scripting languages or shells, and people who are not native English speakers. If you’re a system admin and you don’t really know Windows PowerShell, this is a great way to learn it with help from insiders.

Ready to rock the help? Contact June Blender (juneb@microsoft.com) or Marco Shaw (marco.shaw@gmail.com).


February 18, 2010  3:54 PM

CPU data

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

We all want to know about the CPU(s) in our systems – after all that’s what makes them go

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
$arch = DATA {
ConvertFrom-StringData -StringData @’
0 = x86
1 = MIPS
2 = Alpha
3 = PowerPC
6 = Intel Itanium Processor Family (IPF)
9 = x64
‘@

}

$fam = DATA {
ConvertFrom-StringData -StringData @’
1 = Other
2 = Unknown
3 = 8086
4 = 80286
5 = Intel386™ Processor
6 = Intel486™ Processor
7 = 8087
8 = 80287
9 = 80387
10 = 80487
11 = Pentium Brand
12 = Pentium Pro
13 = Pentium II
14 = Pentium Processor with MMX™ Technology
15 = Celeron™
16 = Pentium II Xeon™
17 = Pentium III
18 = M1 Family
19 = M2 Family
24 = AMD Duron™ Processor Family
25 = K5 Family
26 = K6 Family
27 = K6-2
28 = K6-3
29 = AMD Athlon™ Processor Family
30 = AMD2900 Family
31 = K6-2+
32 = Power PC Family
33 = Power PC 601
34 = Power PC 603
35 = Power PC 603+
36 = Power PC 604
37 = Power PC 620
38 = Power PC X704
39 = Power PC 750
64 = MIPS Family
65 = MIPS R4000
66 = MIPS R4200
67 = MIPS R4400
68 = MIPS R4600
69 = MIPS R10000
80 = SPARC Family
81 = SuperSPARC
82 = microSPARC II
83 = microSPARC IIep
84 = UltraSPARC
85 = UltraSPARC II
86 = UltraSPARC IIi
87 = UltraSPARC III
88 = UltraSPARC IIIi
96 = 68040
97 = 68xxx Family
98 = 68000
99 = 68010
100 = 68020
101 = 68030
112 = Hobbit Family
120 = Crusoe™ TM5000 Family
121 = Crusoe™ TM3000 Family
122 = Efficeon™ TM8000 Family
128 = Weitek
130 = Itanium™ Processor
131 = AMD Athlon™ 64 Processor Famiily
132 = AMD Opteron™ Processor Family
144 = PA-RISC Family
145 = PA-RISC 8500
146 = PA-RISC 8000
147 = PA-RISC 7300LC
148 = PA-RISC 7200
149 = PA-RISC 7100LC
150 = PA-RISC 7100
160 = V30 Family
176 = Pentium III Xeon™ Processor
177 = Pentium III Processor with Intel SpeedStep™ Technology
178 = Pentium 4
179 = Intel Xeon™
181 = Intel Xeon™ Processor MP
182 = AMD Athlon™ XP Family
183 = AMD Athlon™ MP Family
184 = Intel Itanium 2
185 = Intel Pentium M Processor
190 = K7
201 = G4
202 = G5
203 = G6
250 = i860
251 = i960
260 = SH-3
261 = SH-4
280 = ARM
281 = StrongARM
300 = 6×86
301 = MediaGX
302 = MII
320 = WinChip
350 = DSP
500 = Video Processor
‘@

}

$type = DATA {
ConvertFrom-StringData -StringData @’
1 = Other
2 = Unknown
3 = Central Processor
4 = Math Processor
5 = DSP Processor
6 = Video Processor
‘@

}

Get-WmiObject -Class Win32_Processor |
Format-List DeviceID, 
@{Name="Processor Type"; Expression={$type["$($_.ProcessorType)"]}},
Manufacturer, Name, Description,
@{Name="CPU Family"; Expression={$fam["$($_.Family)"]}}, 
@{Name="CPU Architecture"; Expression={$arch["$($_.Architecture)"]}},
NumberOfCores, NumberOfLogicalProcessors, AddressWidth, DataWidth, 
CurrentClockSpeed, MaxClockSpeed, ExtClock,
L2CacheSize, L2CacheSpeed, L3CacheSize, L3CacheSpeed,
CurrentVoltage, PowerManagementSupported,
ProcessorId, SocketDesignation, Status

<

 

The script just uses the Win32-Processor class & selects the relevant properties.  We spend more time defining the data than we do actually running the script!

I’d be interested in hearing what’s the oldest processor discovered with the script – please leave a comment and let us know what you find


February 16, 2010  4:11 PM

Disks: CD Drives

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Just to finish off our look at disks – we’ll have a quick look at CD drives

001
002
003
004
005
006
007
008
009
010
$cds = Get-WmiObject -Class Win32_CDROMDrive 
foreach ($cd in $cds){
    $cd | select Caption, Drive, MediaLoaded, Status, CompressionMethod,
    Manufacturer, MediaType,
    SCSIBus, SCSILogicalUnit, SCSIPort, SCSITargetId,
    TransferRate
    "Capabilities:"
    $cd | select -ExpandProperty CapabilityDescriptions 
    "`n"
}

In this scripts I’m putting the CD Drive information into the variable $cds.  This will be an array of WMI objects – one for each drive.  I can then use foreach to iterate through the drives.

The first select picks off a set of properties as shown – if there isn’t a CD in the drive then transfer rate will be returned as –1

The second select expands the property collection that holds the drive capability descriptions.  Doing it in two hits means I can keep the script simple

Technorati Tags: ,


February 13, 2010  11:08 AM

PowerShell in Practice deal

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Manning are running a Deal of the Day Sunday 14 February for PowerShell in Practice

 

The deal is $15 for the ebook version.  Follow the link from http://www.manning.com/ and use discount code dotd0214

 

Please fell free to communicate to anyone you think may be interested

 

Enjoy

Technorati Tags: ,


February 11, 2010  4:07 PM

VolumeLabels

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Need to read just the volume labels on a system.  Try this

001
002
003
004
005
006
007
008
009
010
011
012
013
014
function Get-VolumeLabel {
param ([string]$computer=".",
       [string]$drive = $null
)
    if ($drive){
        if ($drive -notlike "?:")
        { Throw "Drive should be submitted as letter and colon e.g. C:"}
        $wmiq = Get-WmiObject -Class Win32_LogicalDisk `
         -Filter "DeviceId=’$($drive)’"  -Computer $computer
    }
    else {$wmiq = Get-WmiObject -Class Win32_LogicalDisk -Computer $computer}
   
    $wmiq | select DeviceId, VolumeName
}

 

Technorati Tags: ,


February 9, 2010  3:48 PM

UG Recording

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Thank you to those people who joined the Live Meeting tonight. The recording details are below.  It will be available for 365 days from now.

Richard Siddaway has invited you to view a Microsoft Office Live Meeting recording.
View Recording
Recording Details
    Subject: PowerShell UG
    Recording URL: https://www.livemeeting.com/cc/usergroups/view
    Recording ID: 5JCG5C
    Attendee Key: X8g}hNd[c

This Office Live Meeting invitation is a personal invitation meant only for you. It should not be forwarded. If you received this email by mistake or require Live Meeting Assistance, please refer to the Live Meeting Assistance Center at http://r.office.microsoft.com/r/rlidLiveMeeting?p1=12&p2=en_US&p3=LMInfo&p4=support

The slides and demo scripts can be downloaded from http://cid-43cfa46a74cf3e96.skydrive.live.com/browse.aspx/PowerShell%20User%20Group/February%5E_2010

Technorati Tags: ,


February 8, 2010  2:10 PM

Defragmenting a volume

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

We have seen how to analyse a volume to see if it needs a defrag.  This is how we do it.  Modern windows systems will do a certain amount of defrag work automatically but sometimes we need to help them out.

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
function Start-Defrag {
[CmdletBinding(SupportsShouldProcess=$true)]
param ([string]$computer=".",
       [string]$drive
)
    if ($drive -notlike "?:"){ 
    Throw "Drive should be submitted as letter and colon e.g. C:"}
   
    $filt = "Name=’" + $drive + "\\’"
    $vol = Get-WmiObject -Class Win32_Volume -Filter $filt `
    -ComputerName $computer
   
    $res = $vol.Defrag($false)
   
    if ($res.ReturnValue -eq 0) {
        Write-Host "Defrag succeeded"
        $res.DefragAnalysis | 
        Format-List AverageFileSize, AverageFragmentsPerFile, 
        AverageFreeSpacePerExtent, ClusterSize,
        ExcessFolderFragments, FilePercentFragmentation, 
        FragmentedFolders, FreeSpace, FreeSpacePercent, 
        FreeSpacePercentFragmentation, 
        LargestFreeSpaceExtent, MFTPercentInUse, 
        MFTRecordCount, PageFileSize, TotalExcessFragments, 
        TotalFiles, TotalFolders, TotalFragmentedFiles, 
        TotalFreeSpaceExtents, TotalMFTFragments, 
        TotalMFTSize, TotalPageFileFragments, 
        TotalPercentFragmentation, TotalUnmovableFiles, 
        UsedSpace, VolumeName, VolumeSize 
    }
    else {Write-Host "Defrag failed Result code: " $res.ReturnValue}
}

 

Our function has a computer name and drive as parameters. We check the drive is in the right format and reject if it isn’t.

From that its just a case of getting a WMI object for the volume and calling the defrag method.  The $false parameter means don’t automatically fix problems – we want to deal with those ourselves.

If the return value is 0 – we have a winner and our defrag succeeded. Time to see the results other wise we dump out the return code so we can find out what went wrong

Technorati Tags: ,,,


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: