November 2010 - Posts

January 2011 PowerShell User Group Meeting

Save the date -  11 January 2011  7.30 GMT

 

UK PowerShell User group presents a Live Meeting with Ed Wilson – THE Scripting Guy.

Ed will be talking about: 

Windows PowerShell Best Practices

Learn Windows PowerShell best practices as they apply to each stage of the script development lifecycle. See the differences between working interactively from the Windows PowerShell prompt, writing an inline script, adding basic function, advanced functions and finally the implementation of Windows PowerShell Modules. What is a local best practice for Windows PowerShell development is not the same as a global best practice, and this talk covers those differences.

About Ed Wilson:

Ed Wilson, MCSE, MSCBA, MCT  is the Microsoft Scripting Guy. As such, he writes the popular Hey Scripting Guy blog for Microsoft, speaks at conferences such as TechEd and TechReady. He is very active in the community and has spoken to numerous user groups around the world via Live Meeting and in person. Ed has written numerous books about VBScript, WMI, and Windows PowerShell scripting and his latest release is Windows PowerShell 2.0 Best Practices. In addition he wrote all the scripts for the Windows Vista, Windows Server 2008 and Windows 7 Resource kits. Ed lives in York, South Carolina and Ed has been with Microsoft since 2001. Prior to becoming the writer of the Hey Scripting Guy blog Ed taught scripting workshops worldwide to Microsoft Premier customers.

 

Live Meeting invites to follow

Manning book offer

My publisher, Manning, have a 35-50% off offer running on ebooks between now and 1 December – check out www.manning.com

PowerShell in Practice for Christmas makes a great idea Smile

Posted by RichardSiddaway | with no comments
Filed under: ,

Visio Stencils

If you are looking for Visio stencils – especially of a technical nature – check out Visio cafe - - http://www.visiocafe.com/

Posted by RichardSiddaway | with no comments
Filed under:

PAM 0.4

PowerShell Admin Modules 0.4 is now available.  This adds a PAMSysInfo module to the download that includes the following functions:

Get-BIOSInfo
Get-Bus
Get-CDROM
Get-ComputerSystem
Get-CPU
Get-MemIrq
Get-OSInfo
Get-PageFile
Get-System
Get-TimeZone

Get-SystemInfo is a top level function that calls the others for a full system information dump.  All functions take a computer name as their only parameter.

PAMSysInfo isn’t complete but there is enough to start making it useful

Download from http://psam.codeplex.com/

Enjoy

SC Virtual Machine Manager

Spent the last two evenings trying to install and configure SC VMM.  Total failure.  Kept getting an error about not being able to connect to the agent on the host – this is after the initial failure of trying to install SC VMM on the host.

Nothing worked for me – its odd as we’ve had it working at work.

 

Not worth anymore effort – I’ll stick with WMI and PowerShell.

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

PAM 0.3

I’ve added another module to the PSAM project on codeplex.

Version 0.3 now has:

PAMShares – for working with shares
PAMMath – for working with binary and hex
PAMEnv – for working with environmental variables

The modules can be downloaded from http://psam.codeplex.com/

Enjoy

Posted by RichardSiddaway | with no comments
Filed under: ,

Remove environmental variable

Lets round off looking at environmental variables by looking at how to remove them

001
002
003
004
005
006
007
008
009
010
011
012
013
014

function remove-environment {
param (
 [string][ValidateNotNullOrEmpty()]$name,
 [switch]$perm,
 [switch]$machine
)
$value = ""
if (-not $perm) {Remove-Item -Path env:\$($name) -Force}
else {
 if ($machine){$type = "Machine"}
 else {$type = "User"}
 [System.Environment]::SetEnvironmentVariable($name, $value, $type)
}
}

 

If you want to remove it permanently use the –perm switch otherwise it is just removed from the session

Posted by RichardSiddaway | with no comments
Filed under:

Changing environmental variables

This is similar to creating them.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018

function set-environment {
param
 (
 
[string][ValidateNotNullOrEmpty()]$name,
 [string][ValidateNotNullOrEmpty()]$value,
 [switch]$perm,
 [switch]$machine

)

 
if (-not $perm) {Set-Item -Path env:\$($name) -Value $($value
)}
 
else
 {
 
if ($machine){$type = "Machine"
}
 
else {$type = "User"
}
 
[System.Environment]::SetEnvironmentVariable($name, $value, $type
)
 }
 
 
Get-Item -Path env:\$($name)
}

 

We use the same variables as when creating a variable.  If a permanent change is required we use the –perm switch but remember that the change won’t be seen until PowerShell is restarted

Posted by RichardSiddaway | with no comments
Filed under:

PowerShell and WMI book

A few months ago I started work on a follow up to PowerShell in Practice – http://www.manning.com/siddaway/ .

This book will also be published by Manning. It covers PowerShell and WMI.  These two powerful technologies work well together to give a superb environment for managing your systems. WMI has had a bit of  a bad reputation over the years but PowerShell really does make it easy to work with. 

The first three chapters are available no through the Manning Early Access Program [MEAP] from http://www.manning.com/siddaway2/

Chapters 4 and 5 are in the pipeline and I’m currently working on chapter 6.

Please leave any comments on the author forum or here

Enjoy.

PowerShell in Practice goes mobile

PowerShell in Practice is now available in mobi and epub formats for use on Kindle, iPhone, Sony Reader etc etc

If you have a copy of the book you should be getting emailed about the availability of these new formats.  Otherwise check out http://www.manning.com/catalog/mobile/

Posted by RichardSiddaway | with no comments
Filed under: ,

Create an environmental variable

We can easily use New-Item to work with the environment provider

New-Item -Path env: -Name Myenv -Value "Hello"

but this only creates a variable that lasts the duration of the PowerShell session

 

To create a permanent environmental variable we need to drop down to .NET

[System.Environment]::SetEnvironmentVariable("MyPermEnvVar", "I am here for good", "User")

 

If you want a Machine level variable replace “User” with “Machine”.  if you use “Process” instead its the equivalent of using New-Item in our first example.

The new variable won’t be visible/usable until PowerShell is restarted.

What we need is a function that combines these two approaches.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016

function new-environment {
param
 (
 
[string][ValidateNotNullOrEmpty()]$name,
 [string][ValidateNotNullOrEmpty()]$value,
 [switch]$perm,
 [switch]$machine

)

 
if (-not $perm) {New-Item -Path env:\ -Name $($name) -Value $($value
)}
 
else
 {
 
if ($machine){$type = "Machine"
}
 
else {$type = "User"
}
 
[System.Environment]::SetEnvironmentVariable($name, $value, $type)
 }
}
Posted by RichardSiddaway | with no comments
Filed under:

Variables and the Environment

One of the things I often find myself doing when working on scripts is checking on variables. The cmdlet Get-Variable is useful for this. What I hadn’t realised was that Get-Variable with out any parameters is equivalent to doing Get-ChildItem -Path variable: which gives a quick check on all variables that are defined in your session.

The other area I often poke into is the environment drive. Unfortunately there isn’t a Get-Environment cmdlet.  We can write a simple function to do this for us

 

001
002
003
004
005
006
007

function get-environment {
param ([string]$name = "")
 
 if (!$name){Get-ChildItem -Path env:}
 else{Get-ChildItem -Path env:\$name} 

}
Posted by RichardSiddaway | with no comments
Filed under:

PowerShell PowerCamp

Interested in PowerShell?  Want to learn it fast? Want to learn from an expert?

if so check out http://tfl09.blogspot.com/2010/11/weekend-powershell-camp-event-on-cards.html for info on a weekend event Thomas Lee is running in the UK.

Highly recommended. In fact he is the only PowerShell trainer in England I would recommend.

Posted by RichardSiddaway | with no comments
Filed under:

PowerShell in Practice deal of the day

PowerShell in Practice is Manning’s deal of the day.  Highly recommended Smile

Jump over to http://www.manning.com for 50% off.

offer is for today only

Posted by RichardSiddaway | with no comments
Filed under: ,