One thing that we seem to forget when we use PowerShell is the functionality that was available to us in VBScript through the Windows Scripting Host (WSH) objects. Much of this functionality has been duplicated in PowerShell cmdlets or through .NET classes but there is still a good pile of stuff we can use. I think its time to stir up that pile and have a look at what we can find. The great thing about this functionality is:
- its available on all Windows boxes
- there are many VBScript examples we can reuse
The WScript object is the top of the tree as far as WSH is concerned bit it doesn’t really do much for us. Lets drop down a level and look at the WScript.Shell object.
PS> $wshell = New-Object -ComObject "WScript.Shell"
The properties look interesting lets start there. Special folders are the desktop etc which we will look at later. Current directory is obvious.
The Environment property is listed as a parameterized property – this means we have to give it a value
$wshell = New-Object -ComObject "WScript.Shell"
"System", "User", "Process", "Volatile" |
We have four possibilities which gives us a nice break down of the environmental variables. It supplies a bit more info than
The Environment property may look like a method but it isn’t really.
We do have a set of methods to play with
which we will start looking at later.