PowerShell for Windows Admins


February 4, 2011  11:46 AM

Don’t forget

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The UK PowerShell group has a Live Meeting on Tuesday 8 February at 7.30pm GMT.

Details from:

http://msmvps.com/blogs/richardsiddaway/archive/2011/01/18/uk-user-group-february-live-meeting.aspx

January 28, 2011  1:17 PM

Science or Art

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Infrastructure Architecture = Science or Art. Discuss.

We claim the titles of architect and/or engineer but is what we do as infrastructure architects really based on solid scientific/engineering principles.

I would claim not. Much of what we do is recycling the designs of the past – possibly adapting them as new versions of particular technologies appear. But how many times have you seen an implementation of version 3 of product that is implemented in exactly the same way as version 1 would have been. The reason is usually the very lame “but we’ve always done it that way”. The real reason in many cases is that the people involved haven’t bothered to keep up to date with changes in the technologies they are relying on. This means their organisations aren’t getting the full benefit of those applications.

There are a number of fundamental architectural decisions that in many cases are driven by the existing environment. How many truly green field sites are there these days?

There are a larger number of design decisions which are often based on the products we select.

In this way we are more like the master masons that built the great cathedrals of the Middle Ages. We know what works and we stick with it.

So. Science or Art?


January 25, 2011  2:08 PM

System Restore Points pt 2

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

We have seen how to discover the available restore points.  What about creating one.

001
002
003
004
005
006
007
008
009
010
011
012
013
function new-systemrestorepoint {
[CmdletBinding()]
param ( 
[string]$computername=“.”,
[string]$description=“Testing123″
) $test = Test-Connection -ComputerName $computername -Count 1
if (-not ($test)){Throw “Computer $computername not reachable”

}

 $sr = [wmiclass]“\\$computername\root\default:SystemRestore”
 $sr.CreateRestorePoint($description, 0, 100)
}

 

 

 

 

We need to use [wmiclass] to create a new instance of the SystemRestore class. We can then use the CreateRestorePoint method with the description we’ve input as a parameter. The other paarmeters define it as an application install and begin system change respectively. This are generic enough to be left as is.  They can be made parameters if required


January 23, 2011  1:10 PM

System Restore Points

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

PowerShell 2.0 supplies 4 cmdlets for working with system restore points. 

Disable-ComputerRestore
Enable-ComputerRestore
Get-ComputerRestorePoint
Restore-Computer

This is great but they only work with the local machine. You can test this easily by either looking at the help for each one or use

get-help * -Parameter computer*

to view all of the cmdlets with a computer related parameter.

YOU HAVE TO BE RUNNING POWERSHELL WITH ELEVATED PRIVILEGES FOR THIS TO WORK

Let’s start with Get-ComputerRestorePoint. We can perform this task using

Get-WmiObject -Namespace ‘root\default’ -Class SystemRestore

This starts the display with the oldest restore point. I want it the other way up. 

Get-WmiObject -Namespace ‘root\default’ -Class SystemRestore |
sort SequenceNumber -Descending

I also only want the CreationTime, Sequence number and description

Get-WmiObject -Namespace ‘root\default’ -Class SystemRestore |
sort SequenceNumber -Descending |
Format-Table SequenceNumber, CreationTime, Description –AutoSize

At this point we loose the formatting on the date and it reverts to WMI format.  Well, we know how to deal with that.

Get-WmiObject -Namespace ‘root\default’ -Class SystemRestore |
sort SequenceNumber -Descending |
Format-Table SequenceNumber,
@{Name="Date"; Expression={$($_.ConvertToDateTime($_.CreationTime))}},
Description –AutoSize

Now I want to wrap this into a function

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
function get-systemrestorepoint {
[CmdletBinding()]
param ( 
[string]$computername="."
) 

$test = Test-Connection -ComputerName $computername -Count 1
if (-not ($test)){Throw "Computer $computername not reachable"
}

 Get-WmiObject -Namespace ‘root\default’ -Class SystemRestore `
 
-ComputerName $computername |
 
 
sort SequenceNumber -Descending |
 Format-Table SequenceNumber,
 
 @{Name
="Date"; Expression={$($_.ConvertToDateTime($_.CreationTime))}},
 Description -AutoSize
}

 

 

 

 

I can use this to access the system restore points on remote machines.  This becomes the first function in a new PAM module.  I’ll develop the rest over a series of posts.


January 22, 2011  2:12 PM

Environmental variables

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

Get-WmiObject -Class Win32_Environment | sort Name | select Name, VariableValue

shows the environmental variables that can be seen on the control panel system dialog.

Useful for checking remote machines if the computername parameter is added to Get-WmiObject


January 21, 2011  12:26 PM

First time sighting

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I received an unsolicited job spec today – first time I’ve seen one with PowerShell listed as the essential skill

Now is definitely the time to start learning PowerShell if you haven’t already


January 19, 2011  2:07 PM

get-scripting PowerShell Podcast

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I recently recorded an episode of the get-scripting podcast which is produced by fellow PowerShell MVP Jonathan Medd.  The podcast is available from

http://get-scripting.blogspot.com/2011/01/get-scripting-podcast-episode-21.html

 

During the session we discuss:

 

I enjoyed recording the podcast and hope you will support Jonathan’s efforts by continuing to listen to future episodes


January 18, 2011  3:45 PM

UK User Group–February Live Meeting

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


When: Tuesday, Feb 8, 2011 7:30 PM (GMT)


Where: Live Meeting

*~*~*~*~*~*~*~*~*~*

An introductory session showing how to get the most out of PowerShell’s utility cmdlets. These are
Compare-Object
ForEach-Object
Group-Object
Measure-Object
New-Object
Select-Object
Sort-Object
Tee-Object
Where-Object
Suitable for beginners and the odd possible surprise for experts

Notes


Richard Siddaway has invited you to attend an online meeting using Live Meeting.
Join the meeting.
Audio Information
Computer Audio
To use computer audio, you need speakers and microphone, or a headset.
First Time Users:
To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.
Troubleshooting
Unable to join the meeting? Follow these steps:

  1. Copy this address and paste it into your web browser:
    https://www.livemeeting.com/cc/usergroups/join
  2. Copy and paste the required information:
    Meeting ID: 5D2B4R
    Entry Code: h_>SF*D9q
    Location: https://www.livemeeting.com/cc/usergroups

If you still cannot enter the meeting, contact support

Notice
Microsoft Office Live Meeting can be used to record meetings. By participating in this meeting, you agree that your communications may be monitored or recorded at any time during the meeting.


January 16, 2011  1:09 PM

UK PowerShell User Group Meetings

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Please note the following dates for your diaries:

 

8 February – PowerShell utility cmdlets

An introductory session showing how to get the most out of PowerShell’s utility cmdlets.  These are

Compare-Object
ForEach-Object
Group-Object
Measure-Object
New-Object
Select-Object
Sort-Object
Tee-Object
Where-Object

 

22 March – Regular Expressions

PowerShell MVP Tome Tanasovski will present on Regular Expressions.  This is an opportunity to learn more about an under used part of PowerShell.

Tome is a Windows engineer for a market-leading global financial services firm in New York City. He is a recipient of the PowerShell MVP award, the founder and leader of the New York City PowerShell User group, a blogger, and a regular contributor to Microsoft’s Windows PowerShell forum. He has been featured four times on Hey Scripting Guy, and he is currently working on the PowerShell Bible, which is due out in 2011 from Wiley. 

http://powertoe.wordpress.com

http://twitter.com/toenuff

 

12 April – PowerShell and COM

PowerShell has great support for WMI and .NET but don’t forget that many applications still only have a COM interface. This session will also cover accessing the Windows Scripting Host functionality. 

All sessions start at 7.30pm UK time unless stated otherwise.  (Note that UK goes to daylight saving time on 20 March)


January 13, 2011  1:57 PM

Registry data types

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

One point I didn’t cover in my series on working with the registry was how to get the type of a registry value.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
$regtype = DATA {
ConvertFrom-StringData -StringData 
@’
1 = REG_SZ
2 = REG_EXPAND_SZ
3 = REG_BINARY
4 = REG_DWORD
7 = REG_MULTI_SZ
‘@

}
$HKLM = 2147483650
$key = "SOFTWARE\Microsoft\Windows\CurrentVersion"
$computer="."
$reg = [wmiclass]"\\$computer\root\default:StdRegprov"
$data = $reg.EnumValues($HKLM, $key)
$x = ($data.snames).Length
for ($i=0; $i -le $x; $i++){"{0,-30} {1}" -f
 
  $(
$data.snames[$i]), $regtype["$($data.types[$i])"] 
}

The easiest way is to use the EnumValues() method.  This returns integer values for the type.

Define a hash table that contains the integer and its meaning. Define the hive and the key. Create an instance of StdRegProv and invoke the EnumValues method. Loop through the returned values and use a formatted string to display the results


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: