Your basic ITPro blog... What's going on at work, what I'm interested in.

Friday, April 4, 2008

2008-04-04 PowerShell Exercise

I wanted to share today's exercise because it deals with the Registry. Powershell treats the registry like any other directory. This can be a good thing or a bad thing, depending on your competence. As you know, the Registry is not to be trifled with! That being said, Powershell is a great tool to use to explore and modify the Registry.

Here's a nice blog post that discusses the Registry and Powershell. Googling 'PowerShell Registry' will give you a bunch of great posts as well. It's worth checking out.

And now, for today's QUESTION:

Hey, Scripting Guy! Is there any way to determine the currency symbol that’s in use on a computer?
-- IR

SCRIPTING GUYS SOLUTION:

   1: Const HKEY_CURRENT_USER = &H80000001
   2:  
   3: strComputer = "."
   4:  
   5: Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
   6:  
   7: strKeyPath = "Control Panel\International"
   8: strValueName = "sCurrency"
   9:  
  10: objRegistry.GetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
  11:  
  12: Msgbox strValue

POWERSHELL SOLUTION:

   1: $(Get-ItemProperty 'HKCU:\Control Panel\International').sCurrency

The main thing to remember is that you can use the Registry as you would any other directory. So, you can CD, DIR, etc. through the structure. You can also create, delete, and modify keys and values. Very powerful tool!

P.S. Thank you to everyone who gave me tips on code formatting in blog posts. I got a bunch of recommendations and have landed on this Windows Live Writer Plug-in.

No comments:

Additional Info

My photo
email: support (AT) mangrumtech (DOT) com
mobile: 480-270-4332