Install Windows PowerShell on Windows 7

Hey, Scripting Guy! How do I download Windows PowerShell 2.0 to my new Windows 7 computer? I went to the Microsoft Download page for Windows PowerShell, but I was unable to find a version for Windows 7—surely, you all did not forget to make a version of Windows PowerShell 2.0 for your latest and greatest operating system!

-- TW

Hello TW, Microsoft Scripting Guy Ed Wilson is here to help save the day. You do not have to download Windows PowerShell 2.0 if you have Windows 7 because it is already installed.

Unfortunately, it is kind of hidden. To launch Windows PowerShell, you can use the Search Programs and Files dialog box. All that you have to do is type the word PowerShell and press Enter. The Windows PowerShell console will launch. This is seen in the following figure.

If you do not trust the search box (or simply prefer to mouse around) the Windows PowerShell shortcuts are housed in Start / All Programs / Accessories / Windows PowerShell. This is seen in the following figure.

Personally, I think both of those solutions are too difficult, and I create a shortcut on the task bar. I do this for both the Windows PowerShell console application and the Windows PowerShell ISE (Integrated Script Editor). To create the shortcut I drag both the Windows PowerShell icon and the Windows PowerShell ISE icon with the right mouse button to the desktop. When I let go, a task list appears that asks whether I want to copy, move or create a shortcut. I select create the shortcut, and then drag the shortcut to the task bar with my right mouse button. As I hover over the taskbar, I am prompted if I want to pin to the task bar (of course, I say yes). For information about how to install Windows PowerShell on Windows XP, see the Scripting WifeGets Started with Windows PowerShell post. For information about how to configure the Windows PowerShell shortcuts, and getting started using Windows PowerShell cmdlets, see the Scripting Wife Eases into Windows PowerShell cmdlets post. Generally, the best way to start using Windows PowerShell is to read through the Scripting Wife posts, and to complete the 2010 Scripting Games beginner events. The Scripting Wife goes through the process of learning the basics of Windows PowerShell in order to compete in the 2010 Scripting Games, and her experience is particularly valuable for beginning users.

Detect 32-bit PowerShell

Hey, Scripting Guy! I found this Windows PowerShell tip and wondered if there is a 64-bit version? I copied the code here.

Hello IB, no there is no 64-bit version of the ScriptControl. However, what you can do is make sure that you launch the x86 version of Windows PowerShell when you have to use the ScriptControl. On a 64-bit version of Windows, in the Windows PowerShell program folder (a picture of which appears in my answer to the previous question) there will be 32-bit and 64-bit versions of Windows PowerShell. In my script, I would also perform a text to make sure that I was running in 32-bit, and if not, I would display a message and exit gracefully.

Here is a function that will test for a 32-bit environment.

Function Test-32Bit

{

<#

.Synopsis

Determines whether the computer has a 32-bit processor architecture.

.Description

The Test-32Bit function returns TRUE if the computer has a 32-bit processor

architecture and FALSE if it does not. The function does not have any parameters.

64-bit machines will return true when you run this function in a process running in 32-bit mode

.Notes

Test-32Bit uses the PROCESSOR_ARCHITECTURE environment variable

($env:PPROCESSOR_ARCHITECTURE, %PROCESSOR_ARCHITECTURE) to determine its value.

.Example

C:\PS> Test-32Bit

True

.Link

Test-64Bit

#>

param()

if($env:PROCESSOR_ARCHITECTURE -match '86') { $true } ELSE { $false}

}

If it were me, for this particular example, I would use the .NET Framework Microsoft.visualbasic.Interaction class. I talk about the methods exported by this class in several Hey, Scripting Guy! blog posts. In fact, I have written several posts that talk about how to migrate VBScript code to Windows PowerShell. Here is a bit of code that will display a nice input box.

Read an Offline Registry

Hey, Scripting Guy! I have to update a registry value that resides in the Hkey_Current_User (HKCU) on remote machines. I cannot do it by using remote registry operations for HKCU.

It seems like the only way is to look for the logged on user, then look into the ProfileList in HKLM, then getting the full SID and eventually updating (or reading) the relevant SID hive from HKU.

This will be quite a big job for a PowerShell beginner like me. I was wondering if there is a cmdlet or a script to save me tons of work just to identify which user hive in HKU I have to use.

-- SO

Hello, SO. Unfortunately, there is no really good way to work with HKCU offline, because it is loaded dynamically when a user logs in. It is possible to experiment with the REG.exe command, which can load an offline .reg file, but I have not had good luck working with REG via a Windows PowerShell script.

The only way to really work with HKCU is to work with it via the currently logged on user. This can take place via a logon script, or a scheduled task. Depending on what you are really trying to do, you will actually be better off using Group Policy. The advantage is that with Group Policy, you have a great documented methodology, and can easily filter the application of the registry setting. In addition, you have centralized management, and can easily roll back changes that you deploy if needed.

Working with Security Logs

Hey, Scripting Guy! Our domain controller security logs rollover almost daily. We have recently started to save the logs off. Below is an edited down part of the VBScript that saves the files. Is there a way to open the saved security event logs with VBScript and look for 675 events with failure code 0x18. I have to ask about VBScript because I have not made the jump to PowerShell… yet. If there is a good book to read to pick up PowerShell, here is a good place to mention it.

Hello, DS. If you are saving .evt files, neither VBScript nor Windows PowerShell can directly open and read the files. You have to take a look at LogParser. LogParser can be automated via Windows PowerShell or VBScript if you wish. Here is a document in the TechNet library that talks about working with LogParser. As for Windows PowerShell books, I would be remiss if I did not mention the book I wrote for Microsoft Press, Windows PowerShell 2.0 Best Practices. It is a hefty four pounds, and takes a real-world approach to Windows PowerShell from a network administrator’s perspective.