PowerShell for Windows Admins


June 28, 2010  3:23 PM

PowerShell User Group

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

Don’t forget the PowerShell User Group Live Meeting – Tuesday 29 June @ 7.30 BST

Details from

http://msmvps.com/blogs/richardsiddaway/archive/2010/06/17/powershell-ug-meeting-dns.aspx

June 28, 2010  3:21 PM

Adding a Registry value

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Last time we saw how to add a registry key – this we add a string value to that key

001
002
003
004
005
006
007
008
009
010
$HKLM = 2147483650 #HKEY_LOCAL_MACHINE

$computer = "."  #local machine
$reg = [wmiclass]"\\$computer\root\default:StdRegprov"

$key = "SOFTWARE\ITKE PSAdmins"
$name = "String Entry"
$value = "This is a string"

$reg.SetStringValue($HKLM, $key, $name, $value)

Very similar to last time except after defining the key we define a subkey and its value.  In this case both strings.

The SetStringValue methods is used to create the value. It can also be used to modify the value

 

001
002
003
004
005
006
007
008
009
010
$HKLM = 2147483650 #HKEY_LOCAL_MACHINE

$computer = "."  #local machine
$reg = [wmiclass]"\\$computer\root\default:StdRegprov"

$key = "SOFTWARE\ITKE PSAdmins"
$name = "String Entry"
$value = "This is a string 2"

$reg.SetStringValue($HKLM, $key, $name, $value)

The set methods will alter the value if it present or create it if its not.

Next time we’ll look at some of the other methods and types of data. There is one method for each data type as when we were reading


June 27, 2010  4:33 AM

Adding a Registry Key

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We seen how to read the registry – now its time to look at writing to the registry.

At this point I have to supply the usual warnings about altering the registry – it can damage your machine if things go wrong. In addition registry errors have been blamed for the extinction of the dinosaurs, the big bang and the energy death of the universe – you have been warned  :-)

We’ll start by creating a new key in a safe(-ish) place.  This has the advantage of not altering anything.

 

001
002
003
004
005
006
007
$HKLM = 2147483650 #HKEY_LOCAL_MACHINE

$computer = "."  #local machine
$reg = [wmiclass]"\\$computer\root\default:StdRegprov"

$key = "SOFTWARE\ITKE PSAdmins"
$reg.CreateKey($HKLM, $key)

We need to define the constant for the HKLM hive, define the machine we are interested in – this could be a parameter to our script/function.

Create the WMI object for the registry, define the key to be created and then use the CreateKey method to actually perform the creation.  Use regedit to confirm the result or use the PowerShell registry provider

Get-ChildItem -Path hklm:\software\itk*


June 22, 2010  1:56 PM

Transparency Policy

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

If you haven’t see the ITKE transparency policy – it is available here

http://itknowledgeexchange.techtarget.com/itke-community-blog/the-it-knowledge-exchange-transparency-and-accuracy-policy/

If for any reason you think I have posted anything that breaches this please leave a comment so that I can amend the post as appropriate


June 22, 2010  1:53 PM

Reader Survey

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

ITKE are performing a reader survey.

http://itknowledgeexchange.techtarget.com/itanswers/new-contest-you-could-win-a-new-xbox-360/
http://www.surveygizmo.com/s3/314286/ITKE-Member-Survey-June-2010

Please participate


June 17, 2010  1:05 PM

PowerShell UG Meeting: DNS

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


When: Tuesday, Jun 29, 2010 7:30 PM (BST)


Where: Live Meeting webcast

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

Meeting will cover DNS, DNS best practice analyser, DNS WMI provider and DNSShell cmdlets from codeplex

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: NPP98R
    Entry Code: Dj\J_)4}g
    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.


June 11, 2010  1:10 PM

Manning Deal of the Day

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

PowerShell in Practice pbook is today’s deal of the day at www.manning.com  – enter dotd0611cc in Pormotional Code box on check out


June 9, 2010  12:56 PM

Reading the Registry – time service

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I recently needed to look at the time service configuration on a number of machines.  We can use what we have learned about reading registry keys with WMI to do this

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
$HKLM = 2147483650 #HKEY_LOCAL_MACHINE
$reg = [wmiclass]‘\\.\root\default:StdRegprov’

$key = "SYSTEM\CurrentControlSet\Services\W32Time\Config"
$value = "MaxPosPhaseCorrection"
$maxpos = $reg.GetDwordValue($HKLM, $key, $value)  ## REG_DWORD
 
$value = "MaxPosPhaseCorrection"
$maxneg = $reg.GetDwordValue($HKLM, $key, $value)  ## REG_DWORD

$key = "SYSTEM\CurrentControlSet\Services\W32Time\Parameters"
$value = "NtpServer"
$srvr = $reg.GetStringValue($HKLM, $key, $value)  ## REG_SZ

"Time Settings"
"Server : $($srvr.sValue)"
"Max Positive : $(($maxpos.uvalue)/3600) hours"
"Max Negative : $(($maxneg.uvalue)/3600) hours"

Set the constant for HKLM hive and create a WMI object.  I’ve used the local machine but change the string to

‘\\computer_name\root\default:StdRegProv’ if you want to access a remote machine.

We then set the key and the value we want to read and call the appropriate method.  As a finished I’ve displayed the data in a nicely formatted table.  The maximum negative and positive values are given in seconds so I’ve converted them to hours to be more understandable.


June 6, 2010  12:47 PM

List Registry subkeys

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We recently looked at reading Registry values. http://itknowledgeexchange.techtarget.com/powershell/reading-registry-values/

Before we can do this we need to be able to work out what subkeys are present for a given Registry key.  The WMI StdRegProv class gives us a method for doing this – EnumKeys

001
002
003
004
005
$HKLM = 2147483650
$key = "SYSTEM\CurrentControlSet\Services"
$reg = [wmiclass]‘\\.\root\default:StdRegprov’
$subkeys = $reg.EnumKey($HKLM, $key)
$subkeys.snames

Using the HKLM constant and defining a key to investigate we create an instance of StdRegProv and call the EnumKey method. The results are put into the $subkeys variable. The snames property contains the names of the subkeys


June 5, 2010  6:30 AM

PowerShell in Practice – published

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The book is finally complete and available in its final form.  The ebook is available now from http://www.manning.com/siddaway/ and the print version will be available 7 June 2010.

Enjoy


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: