June 2010 - Posts

Testing a path

Until recently VBScript was king for admin scripting in the Windows environment. This set up a certain way of doing things in people’s minds. I saw a lot of that in the Scripting Games. One example that comes to mind is testing if a path exists.

In PowerShell we can do

Test-Path -Path c:\test\test1.txt

which on my system will return true (at the moment).  If I change it to

Test-Path -Path c:\test\test2.txt

I’ll get false as the answer.  The important point to remember is that these are boolean values being returned from the System.Boolean class not text saying “true” or “false”

I saw a lot of this structure

$test = Test-Path -Path c:\test\test2.txt
if ($test -match "false"){New-Item -Path c:\test -Name test2.txt -ItemType File}

 

Another option I saw was

if ($test -eq $false){New-Item -Path c:\test -Name test2.txt -ItemType File}

 

A better way, from a PowerShell perspective is to do this

if (!(Test-Path -Path c:\test\test2.txt)){New-Item -Path c:\test -Name test2.txt -ItemType File}

 

We do the test-path as part of the if test condition and create the file if test-path returns false

Keep it simple and use the power that is delivered when you install PowerShell

Posted by RichardSiddaway | with no comments

Netbook

After recently reviewing the book on netbooks I decided to buy one.  I have a couple of uses that immediately came to mind:

  • running my ebook reader software – its a lot easier to hold the netbook and the screen is big enough and clear enough to read with ease
  • acting as my mobile reference – I have a lot of technical reference material that I need to access on a fairly regular basis. This makes it easier especially on customer sites that don’t allow the use of memory sticks
  • its easier for  travelling when all I need is Internet and basic Office products.

I ended up with an HP Mini.  I’ve used HP machines quite a bit over the years and always found them reliable. One slight cause for concern was the 1GB of RAM but Windows 7 Starter edition works very well. The machine is responsive and I especially like the keyboard. The touchpad is another matter but I’ve never really liked them anyway.

I ripped off all the junk that seems to ship with a machine these days, installed office 2010, my reader software and MS Security Essentials and I’m good to go.  Battery life seems really good.

And best of all – it has PowerShell installed already.

More updates after I’ve played with it a bit more.

Posted by RichardSiddaway | with no comments
Filed under:

Restore points

One really good idea I saw in the recent Scripting Games concerned modifying the registry.  How many times have you seen the warning – modifying the registry is dangerous, it can wreck your laptop, cause global warming and lead to the energy death of the universe.

One way to avoid these calamities is to create a restore point on your computer before making the changes. Another way is to use transactions but we’ll cover that another time.

Creating a restore point in PowerShell v2 is easy – just use the checkpoint-computer cmdlet

Checkpoint-Computer -Description "Test for blog" -RestorePointType MODIFY_SETTINGS

Other types are available:

  • APPLICATION_INSTALL
  • APPLICATION_UNINSTALL
  • DEVICE_DRIVER_INSTALL
  • MODIFY_SETTINGS
  • CANCELLED_OPERATION

In the event of a problem and you need to roll back Restore-Computer is used but first you have to find the restore points which we can do with

Get-ComputerRestorePoint

All we do then is

Restore-Computer -RestorePoint 227

or whatever sequence number you need from the output of Get-ComputerRestorePoint.

A simple way to protect your computer and still get the job done.

as a final word you do need to run PowerShell as an administrator to work with restore points.

Posted by RichardSiddaway | with no comments
Filed under:

PAM 0.2

I’ve released the second module for the PowerShell Admin Modules tonight.  It is available from

http://psam.codeplex.com/releases/view/46364

This release includes two modules.

PAMShare (originally in PAM 0.1) contains the following functions:

  • Get-Share
  • Get-ShareAccessMask
  • Get-ShareSecurity
  • New-Share
  • Remove-Share
  • Set-Share

Get-Share can now accept a wildcard  eg get-share t*

New-Share now has the share name as first parameter and path as the second.

Both of these changes are the result of feed back on the issues page

The second module is PAMMath.  It contains functions for working with binary and hex numbers

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

A help file is supplied with each module.

Enjoy

Posted by RichardSiddaway | with no comments
Filed under: , ,
More Posts « Previous page