May 2010 - Posts

Windows Netbooks: The Path to Low Cost Computing

 

Author: James Floyd Kelly

Publisher: Apress

ISBN: 978-1-4302-2399-3

My usual three criteria for judging a book are:

  • 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?

I came to this book more intrigued than anything.  I’d not really considered using a netbook – they are too small to do what I want. Right?  So I wanted to learn more and find out if my ideas were right.

At 202 pages this isn’t a massive book and the ratio of screen shots to text is pretty high so it is a fairly quick read.

The book contains 12 chapters and three appendices:

  • 1 The Netbook
  • 2 Netbook Hardware Option
  • 3 Netbook Maintenance
  • 4 Netbook Software Options
  • 5 Netbook and Google Docs
  • 6 Netbook and Malware Protection
  • 7 Netbook Web Browsers
  • 8 Netbook Email
  • 9 Netbook Calendar
  • 10 Netbooks and OpenOffice.org
  • 11 Windows 7 and Netbooks
  • 12 Finding Great Netbook Apps
  • A Netbook manufacturers
  • B Upgrading a Netbook to Windows 7
  • C additional Netbook Apps to consider

Chapter 1 opens the discussion with a review of exactly what a netbook is and why they are so useful. A jog through the main hardware components and a look at how they can influence your purchasing decisions completes the chapter. Chapter 2 follows straight on with a look at the extras you may want – USB hub, pen drive, external CD\DVD, mouse, keyboard etc. Chapter 3 gives a few hints on the watering (not literally) and feeding of netbooks.

By chapter 4 we’re looking at software.  A computer’s great but you can’t do anything without software. Open Source and Cloud computing get the most space here – especially openoffice.

Chapters 5, 8 and 9 are straight advertising copy for Google Docs, Google Mail and Google Calendar respectively.  Ok so as the author you love these but there are alternatives and in some cases much better alternatives.

Chapter 6 covers Malware with so good information on free AV products. The section on SpyBot is overdone.  If your netbook runs Windows 7 it has Windows Defender – works for me.

The brower is next with chapter 7 mainly given over to a discussion of Firefox. Chapter 10 returns to OpenOffice but agian doesn’t mention alternatives.

In chapter 11 we look at windows 7 on netbooks – good recommendation to get one with it installed. A check at a PC retailer today showed most have it installed. The book was published in October 2009 and is already showing its age.

Chapter 12’s discussion on applications spends too long explaining how to search the Internet. The bit at the end on online software repositories was worth waiting for. I also tried Attack of the Buggles (page 182) the book was almost worth it for that alone!

The appendices do what they say with Appendix C being an extension of chapter 12.

So in summary what do I think of the book:

  • technically it is accurate but on the light side.  Don’t look here for an in-depth discussion of the technologies. I’d give it 7/10
  • does it deliver on the material – yes. After reading this you would have a good idea of waht a netbook can do and if its for you - - 8/10
  • is it worth buying and reading. Not sure if I’d be totally happy if I’d bought it but it was worth the read. – 8/10

Overall, it made me think about netbooks and their place in the scheme of things – I might actually be getting one soon as I can see so uses for one – especially now I can get Windows 7 on one. - - 8/10

I think the book will suffer because of the rapid changes in this area of technology. Another edition in 12 months wouldn’t go amiss – if it was an ebook it would be quicker to update.

Posted by RichardSiddaway | with no comments
Filed under: , ,

PowerShell in Practice ebook deal

I know there isn’t much of today left but if you are quick its possible to get an ebook version of PowerShell in Practice for $15.  See the deal of the day at http://www.manning.com/

Posted by RichardSiddaway | with no comments
Filed under: ,

Query me no more

One of the things I noticed in the recent Scripting Games was that a lot of the scripts would do things like this

$query = "Select MaxClockSpeed from Win32_Processor"
$proc = Get-WmiObject -Query $query
Write-Host "Speed: " $proc.MaxClockSpeed

Create a query to access the Win32_Processor class to get the MaxClockSpeed.  Run the query and then use Write-Host to format and output the results.  We’ll come back to use Write-Host like this another time.

This construction is based on the way things used to be done with VBScript.  With PowerShell we have much easier ways to get to the same result.

Get-WmiObject -Class Win32_Processor | Format-List MaxClockSpeed

will produce the same answer. if you really need the formatting

Get-WmiObject -Class Win32_Processor | Format-List @{Name='Speed'; Expression={$_.MaxClockSpeed}}

or even

Write-Host "Speed: " (Get-WmiObject -Class Win32_Processor).MaxClockSpeed

Get-WmiObject does a great job of returning the information from a WMI class. Use its power and simplicity to make your scripts quicker to write and easier to understand

Quick ping

If you’ve used ping before you’ll know that it normally returns four replies from the target.  In PowerShell we have Test-Connection which does the same job. It also normally returns four replies.

When I’m working with remote machines I often want to check they are available before sending a command – especially a WMI command that can take a long time to time out.

 

001
002
003
004
005
006
007
"rslaptop01", "127.0.0.1" | 
foreach {
    if (Test-Connection $_ -Count 1) {
        Get-WmiObject -ComputerName $_ -Class Win32_LogicalDisk -Filter "DriveType='3'" |
        select SystemName, DeviceID, Size, FreeSpace
    }
}

 

To speed up the process use the –Count parameter on test-connection and only get 1 reply.  Quick test to see if he system is there and then run the rest of the code

UG May 2010 Recording, Slides and demo

Thank you to everyone who joined the Live Meeting this evening. Hope you enjoyed the session on PowerShell events.

The slides and demo files are available from

http://cid-43cfa46a74cf3e96.skydrive.live.com/browse.aspx/PowerShell%20User%20Group/May%202010

 

The recording can be viewed on line

View Recording
Recording Details
    Subject: PowerShell Events
    Recording URL: https://www.livemeeting.com/cc/usergroups/view
    Recording ID: 39Q7T9
    Attendee Key: Q&x!_63dP

PowerShell UG reminder

 

Next Live Meeting is Tuesday 18 May at 7.30pm BST

Subject is PowerShell Jobs and Events

Details of the Live Meeting from: http://msmvps.com/blogs/richardsiddaway/archive/2010/05/03/powershell-ug-may-2010.aspx

hey ho hey ho its off to print we go

PowerShell in Practice will be going to the printers next week.

Between now and 21 May 2010 you can get 40% off of PowerShell in Practice (and other Manning books that are in the final stages of production)

Use promotional code m1440 at checkout from www.manning.com

Posted by RichardSiddaway | 2 comment(s)
Filed under: ,

PSCX 2.0 install

I mentioned last time that PSCX 2.0 was available. There is a very wide range of functionality available in the form of functions and cmdlets:

Cmdlets

Add-PathVariable                        Clear-MSMQueue                          ConvertFrom-Base64
ConvertTo-Base64                        ConvertTo-MacOs9LineEnding              ConvertTo-Metric
ConvertTo-UnixLineEnding                ConvertTo-WindowsLineEnding             Convert-Xml
Disconnect-TerminalSession              Expand-Archive                          Export-Bitmap
Format-Byte                             Format-Hex                              Format-Xml
Get-ADObject                            Get-AdoConnection                       Get-AdoDataProvider
Get-AlternateDataStream                 Get-Clipboard                           Get-DhcpServer
Get-DomainController                    Get-DriveInfo                           Get-EnvironmentBlock
Get-FileTail                            Get-FileVersionInfo                     Get-ForegroundWindow
Get-Hash                                Get-HttpResource                        Get-LoremIpsum
Get-MountPoint                          Get-MSMQueue                            Get-OpticalDriveInfo
Get-PathVariable                        Get-PEHeader                            Get-Privilege
Get-PSSnapinHelp                        Get-ReparsePoint                        Get-ShortPath
Get-TabExpansion                        Get-TerminalSession                     Get-TypeName
Get-Uptime                              Import-Bitmap                           Invoke-AdoCommand
Invoke-Apartment                        Join-String                             New-Hardlink
New-Junction                            New-MSMQueue                            New-Shortcut
New-Symlink                             Out-Clipboard                           Ping-Host
Pop-EnvironmentBlock                    Push-EnvironmentBlock                   Read-Archive
Receive-MSMQueue                        Remove-AlternateDataStream              Remove-MountPoint
Remove-ReparsePoint                     Resolve-Host                            Send-MSMQueue
Send-SmtpMail                           Set-BitmapSize                          Set-Clipboard
Set-FileTime                            Set-ForegroundWindow                    Set-PathVariable
Set-Privilege                           Set-VolumeLabel                         Skip-Object
Split-String                            Start-TabExpansion                      Stop-TerminalSession
Test-AlternateDataStream                Test-Assembly                           Test-MSMQueue
Test-Script                             Test-UserGroupMembership                Test-Xml
Unblock-File                            Write-BZip2                             Write-Clipboard
Write-GZip                              Write-Tar                               Write-Zip

 

functions

Add-DirectoryLength                     Add-ShortPath                           Dismount-VHD
Edit-File                               Edit-HostProfile                        Edit-Profile
Enable-OpenPowerShellHere               Get-Help                                Get-PropertyValue
Get-ScreenCss                           Get-ScreenHtml                          Get-ViewDefinition
help                                    Invoke-BatchFile                        Invoke-Elevated
Invoke-GC                               Invoke-Method                           Invoke-NullCoalescing
Invoke-Reflector                        Invoke-Ternary                          less
Mount-VHD                               New-HashObject                          Out-Speech
QuoteList                               QuoteString                             Resolve-ErrorRecord
Resolve-HResult                         Resolve-WindowsError                    Set-LocationEx
Set-ReadOnly                            Set-Writable                            Show-Tree
Stop-RemoteProcess

 

Download the zip file, unblock it, unzip and copy the pscx folder and all sub folders to a folder on your modules path. Couldn’t be easier. To get the functionality

Import-Module pscx

Posted by RichardSiddaway | with no comments
Filed under: ,

PowerShell Community Extensions 2.0

I’ve mentioned the Community Extensions many times in these posts. Version 2.0 is now available http://www.codeplex.com/wikipage?ProjectName=Pscx.

It installs as a PowerShell module – much easier and neater.

I’ve blogged about the beta a few times – if you didn’t try the beta go and get the RTM

Posted by RichardSiddaway | with no comments
Filed under: ,

Hex Subtraction

Again this takes the pattern from the binary function and adapts it to work with hex

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
## this will always subtract value2 from value1
function Get-HexDifference {
param(
    [string]$inputvalue1,
    [string]$inputvalue2
)
## check valid hex numbers
    Test-Hex $inputvalue1
    Test-Hex $inputvalue2

    $diff = (ConvertTo-Decimal -inputvalue $inputvalue1 -hex) `
     - (ConvertTo-Decimal -inputvalue $inputvalue2 -hex)

    if ($diff -lt 0){Throw "Hex subtraction produces negative number"}
    else {ConvertTo-Hex -inputvalue $diff}
}

 

As with the binary subtraction function we test to see if we’ve gone negative – if so reject the value.

 

That’s the end of the math module for now.  As soon as I’ve done the help files I’ll post it on codeplex.

Posted by RichardSiddaway | with no comments
Filed under: , ,

Hex Addition

We’ve looked at the binary functions – now its time to look at the hex functions starting with addition.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
function Get-HexSum {
param(
    [string]$inputvalue1,
    [string]$inputvalue2
)
## check valid hex numbers
    Test-Hex $inputvalue1
    Test-Hex $inputvalue2

    $sum = (ConvertTo-Decimal -inputvalue $inputvalue1 -hex) `
    + (ConvertTo-Decimal -inputvalue $inputvalue2 -hex)

    ConvertTo-Hex -inputvalue $sum
}

This is a direct copy of the binary addition function – just changed to accept hex input instead.

Again we test the hex number is actually hex – convert to decimal, add, and convert back to hex

Establishing a pattern helps make things easier for producing related functions.

Posted by RichardSiddaway | with no comments
Filed under: , ,

Book review: Managing VMware Infrastructure with Windows PowerShell

Author: Hal Rottenberg

Publisher: Sapien Press

ISBN: 978-0-9821314-0-4

If you’ve not read one of my reviews before I have three main criteria for judging a book:

· 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?

This is a relatively short book at 359 pages

After an Introduction the book is divided into the following chapters:

1. Windows PowerShell Crash Course

2. Getting Started

3. Scripting with Virtual Interface

4. Inventory and Reporting

5. Deployment and Configuration

6. Maintenance and Operations

7. Troubleshooting and problem resolution

An appendix deals with Managing VMware with PowerGUI. I haven’t got into this yet as I still prefer running scripts. I will probably end up creating a PowerGUI powerpack of them for use at work – sorry these can’t be shared.

This may seem like a short list but there is a massive amount of information packed into these chapters. The book is written using PowerShell 1.0. I’m running the VI Toolkit on PowerShell 2.0 against vsphere 4. It all works. The toolkit enables us to perform tasks against the host and the guests in a virtual environment.

Chapter 1 is an introduction covering installation, configuration and the key features of PowerShell such as the pipeline and key cmdlets. Chapter 2 is a very short chapter that introduces the VI Toolkit and the PowerShell cmdlets for VMware.

In chapter 3 we start to look at PowerShell scripts and how the VI Toolkit works with PowerShell. The contents of chapters 4-7 are explained by their titles. I found the information in these chapters to be useful and accurate with the examples ready to use.

Judging against my criteria:

· Is it technically accurate? From a PowerShell aspect yes it is. From a PowerShell aspect everything I’ve tried works as described so again I have to give 10/10 for technical content.

· Does it deliver the material it claims to deliver? Oh yes. I found the examples easy to use and they work. It shows how to use PowerShell against VMware. 10/10

· Is worth the cost of purchase and the time I spend reading it? Very definitely. Its already saved me the purchase price several times over and I’m just on the Inventory and Reporting chapter! This very definitely is a book that repays reading – 10/10

The index is will put together as I was able to find everything I needed. Overall score has to be 10/10.  This is one of the best books I’ve bought in a long time.

Before we get too carried away I think the typesetting could have been better – the headings don’t always stand out on the page which can make following the chapters a bit difficult in some places – that’s the only negative I can find.

I haven’t had any need to delve into VMware in any detail until just recently but I did try out the VI Toolkit when it was first in beta. This book is my way into the bits of VMware I need. If you are working with VMware and use PowerShell you should have a copy of this book. If you don’t you should go an buy one – now.

Bitwise Operations

Continuing our look at binary operations I decided I wanted to be able to perform the bitwise operations – band, bor, bxor and get the results back as binary.  We already have operators for these actions in PowerShell so its just a matter of wrapping the appropriate conversion code around them.  I’ll show the code for band here.  The other two are very similar and will be available in the module when I post it on codeplex.

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
function Get-BinaryAND {
param(
    [string]$inputvalue1,
    [string]$inputvalue2,
    [switch]$showsum
)
    if ($inputvalue1.length -ne $inputvalue2.length){Throw "Input values must be same length"}

## check valid binary numbers
## move this to a validation test
    Test-Binary $inputvalue1
    Test-Binary $inputvalue2

    $res = (ConvertTo-Decimal -inputvalue $inputvalue1 -binary) `
         -band (ConvertTo-Decimal -inputvalue $inputvalue2 -binary)
    $ans = (ConvertTo-Binary -inputvalue $res).PadLeft($inputvalue1.length, "0")
    if ($showsum) {
        $inputvalue1
        $inputvalue2
        "-" * $inputvalue1.length
        $ans
    }
    else {
        $ans
    }
}

 

Two binary numbers as input as we saw in the addition\subtraction functions.  I have changed the names to be consistent across the module. Perform the standard checks and then convert them to decimal and perform the band. The result is converted back to binary – padding left with zeros if required.

I decided to show the inputs and output if required – may be a good learning tool to understand this.

 

usage is straight forward

PS> Get-BinaryAND -inputvalue1 1010 -inputvalue2 0011
0010
PS> Get-BinaryAND -inputvalue1 10111010 -inputvalue2 01110011 -showsum
10111010
01110011
--------
00110010

The module contents stand at

ConvertTo-Binary
ConvertTo-Decimal
ConvertTo-Hex
Get-BinaryAND
Get-BinaryDifference
Get-BinaryOR
Get-BinarySum
Get-BinaryXOR
Test-Binary
Test-Hex

I need to add a couple of functions to do hex addition and subtraction and then its done

Posted by RichardSiddaway | with no comments
Filed under: ,

Scripting Games comments X: String Substitution 2

Noticed something like this while judging scripts last week

PS> $comp = Get-WmiObject -Class Win32_ComputerSystem
PS> $mem =  ($comp.TotalPhysicalMemory / 1GB).ToString() + "GB"
PS> $mem
2.74846267700195GB

The value was been divided by 1GB – good -  and then being converted to a string so could add a suffix.

Its easier to do this

PS> $mem = "$($comp.TotalPhysicalMemory / 1GB)GB"
PS> $mem
2.74846267700195GB

Unless of course you want to format the string a bit further

PS> $mem = "{0:F2}GB" -f $($comp.TotalPhysicalMemory/1gb)
PS> $mem
2.75GB

We can use the .NET formatting to format the number of decimal places or going back to our original

PS> $mem =  ($comp.TotalPhysicalMemory / 1GB).ToString("F2") + "GB"
PS> $mem
2.75GB

Lots of ways to format numbers into strings – pick what’s easiest for your particular job

Posted by RichardSiddaway | with no comments

Binary Subtraction

Continuing our look at maths functions in binary (hex is to come) lets have a quick look at subtraction

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
function Get-BinaryDifference {
param(
    [string]$value1,
    [string]$value2
)
## check valid binary numbers
## move this to a validation test
    Test-Binary $value1
    Test-Binary $value2

    $diff = (ConvertTo-Decimal -inputvalue $value1 -binary) -`
     (ConvertTo-Decimal -inputvalue $value2 -binary)

    if ($diff -lt 0){Throw "Binary subtraction produces negative number"}
    else {ConvertTo-Binary -inputvalue $diff}
}

 

Always assume that value2 will be subtracted from value1 therefore value2 should be smaller.

The function is the same as the addition except we perform a subtraction :-)

And we check to see if we have a negative result.  If so throw a wobbly and end the action.

These binary and hex functions will be the next module added to PSAM on codeplex

HA and DR book

The first chapter of my latest book for RealTime Publishers is available for free download. The title is The Shortcut Guide to Understanding the Differences Between High Availability and Disaster Recovery.

Download from http://nexus.realtimepublishers.com/sgudb.php

Binary Addition

We recently looked at converting numbers to binary and hex.  I then thought that I sometimes need to perform simple arithmetic in these bases so – binary addition.

We can use the functions we already have.  Convert a couple of numbers to binary

PS> $a = Convert-ToBinary -inputvalue 51
PS> $b = Convert-ToBinary -inputvalue 39
PS> $a
110011
PS> $b
100111

sum them by converting the binary back to decimal, performing the sum and converting back to binary.

PS> $c = Convert-ToBinary -inputvalue ((Convert-ToDecimal -inputvalue $a -binary) + (Convert-ToDecimal -inputvalue $b -binary))
PS> $c
1011010

A quick check on the result

PS> Convert-ToDecimal -inputvalue $c -binary
90

That works OK  but its a bit messy – too much typing. So I wrote Get-BinarySum

001
002
003
004
005
006
007
008
009
010
011
012
013
014
function Get-BinarySum {
param(
    [string]$value1,
    [string]$value2
)
## check valid binary numbers
## move this to a validation test
Test-Binary $value1
Test-Binary $value2

$sum = (Convert-ToDecimal -inputvalue $value1 -binary) + (Convert-ToDecimal -inputvalue $value2 -binary)

Convert-ToBinary -inputvalue $sum
}

 

Get the two binary numbers – test that they are binary.  Test-Binary is a helper function created from the code used in Convert-ToDecimal

The sum is performed by converting each binary to a decimal, summing them and converting the result back to a binary.

Bingo.  This forms the framework for other functions.

Posted by RichardSiddaway | with no comments
Filed under: , ,

Scripting Games Comments IX: test-path

One more event to go after today and the Games begin to wind down.  I’ve looked at over 1000 scripts – mainly PowerShell – over the course of the Games and have been very impressed with the standard of the entries. There have been some very innovative answers – I suspect that some of the innovation has been due to not knowing how to do something in PowerShell and looking for ways  round that gap.

I’ve posted a number of comments on things I’ve noticed and there are a few more to come.  Some waiting on the closure of events,

One thing I did notice was the use of Test-Path

PS> Test-Path c:\scripts
True

PS> Test-Path c:\scriptz
False

Test-Path returns a boolean – true\false

If you want to use test-path in a test just use

if (Test-Path c:\scripts){}

or

if (-not(Test-Path c:\scriptz)){}

Nice easy single step

Posted by RichardSiddaway | with no comments

Scripting Games Comments VIII: Creating Objects

One thing we have to do quite frequently is create an object and populate some variables.  In PowerShell v1 we would do something like this

001
002
003
004
005
006
007
008
$r = Get-WmiObject -Class Win32_OperatingSystem
$system = New-Object System.Management.Automation.PSObject

Add-Member -InputObject $system -MemberType Noteproperty -Name SystemDevice -Value $r.SystemDevice
Add-Member -InputObject $system -MemberType Noteproperty -Name SystemDrive -Value $r.SystemDrive
Add-Member -InputObject $system -MemberType Noteproperty -Name SystemDirectory -Value $r.SystemDirectory

$system

 

We get some data – in this case from WMI

We use New-Object to create an object – I’ve used the full type name deliberately

$system = New-Object PSObject

works just as well.

Add-Member is used to add three NoteProperties and then we display the object to get

SystemDevice                             SystemDrive                              SystemDirectory                       
------------                             -----------                              ---------------                       
\Device\HarddiskVolume2                  C:                                       C:\Windows\system32
                   

Its a bit of a contrived example but it works.

It is possible to make this a bit easier and less typing

001
002
003
004
005
006
007
008
$r = Get-WmiObject -Class Win32_OperatingSystem
$system = New-Object System.Management.Automation.PSObject

$system | Add-Member -MemberType Noteproperty -Name SystemDevice -Value $r.SystemDevice -PassThru |
Add-Member -MemberType Noteproperty -Name SystemDrive -Value $r.SystemDrive -PassThru |
Add-Member -MemberType Noteproperty -Name SystemDirectory -Value $r.SystemDirectory

$system

 

Add-Member has a –PassThru parameter that enables us to pipeline the property creations.

PowerShell v2 makes it even easier

001
002
003
004
005
006
007
008
$r = Get-WmiObject -Class Win32_OperatingSystem
$system = New-Object System.Management.Automation.PSObject -Property @{
        SystemDevice = $r.SystemDevice 
        SystemDrive  = $r.SystemDrive 
        SystemDirectory = $r.SystemDirectory
    }

$system

 

New-Object does all the work for us – it even creates each property as a NoteProperty.  All we do is give the property information as a hash table.  If you want this all on one line then separate each pair by a semi-colon “;”

Scripting Games Comments VII: File Names

In a number of the events it has been necessary to play around with file names.  I’ve seen a number of ways to get the actual file name ie. without the extension.  The easiest way I know is to use the basename property.

Get-ChildItem | where {!$_.PSisContainer}

returns a list of files – it drops the subfolders.  The file names contain the extension. This will show the relationship between the different parts of the name

Get-ChildItem | where {!$_.PSisContainer} | Format-table FullName, Name, BaseName, Extension –AutoSize

FullName                       Name                BaseName        Extension
--------                       ----                --------        ---------
C:\scripts\auto.csv            auto.csv            auto            .csv
C:\scripts\computers.txt       computers.txt       computers       .txt
C:\scripts\emptyfolders.txt    emptyfolders.txt    emptyfolders    .txt

so if you only need the name

Get-ChildItem | where {!$_.PSisContainer} | select basename

Posted by RichardSiddaway | with no comments
More Posts Next page »