How Do I Install PowerShell on Windows 7 and Other Questions

How Do I Install PowerShell on Windows 7 and Other Questions

  • Comments 5
  • Likes

  

Summary: Learn how to install Windows PowerShell on Windows 7, how to detect 32-bit PowerShell, or how to read an offline registry.

 

In this post:

 

Install Windows PowerShell on Windows 7

Hey, Scripting Guy! QuestionHey, 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

 

Hey, Scripting Guy! AnswerHello 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.

 

NOTE: For information on how to install Windows PowerShell 3.0 on Windows 7, see this Hey Scripting Guy blog article: Install PowerShell 3 on Windows 7.

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! QuestionHey, Scripting Guy!  I found this Windows PowerShell tip and wondered if there is a 64-bit version? I copied the code here.

$a = new-object -comobject MSScriptControl.ScriptControl
$a.language = "vbscript"
$a.addcode("function getInput() getInput = inputbox(`"Message box prompt`",`"Message Box Title`") end function" )
$b = $a.eval("getInput")


Unfortunately I receive the following error when I try to run the code. I believe it is because I have a 64-bit version of Windows 7, and the component is 32-bit.

New-Object : Retrieving the COM class factory for component with CLSID {0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC}

failed due to the following error: 80040154.

Thanks.
-- IB

 

Hey, Scripting Guy! AnswerHello 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.

# ---------------------------------------------------------------------------------------------------

# DotNetInputBoxV2.ps1

# ed wilson, msft, 10/9/2008

#

# uses the .Net framework interaction class with the inputbox method to

# create an inputbox using the dot net framework classes. the microsoft.visualbasic

# namespace is not loaded by default

#

# ---------------------------------------------------------------------------------------------------

#Requires -version 2.0

$prompt = "Enter your command"

$title = ".net example"

$default = "default value"

 

Add-Type  -AssemblyName microsoft.visualbasic

$return = [Microsoft.VisualBasic.interaction]::inputbox($prompt,$title,$default)

$return

 

Read an Offline Registry

Hey, Scripting Guy! QuestionHey, 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

 

Hey, Scripting Guy! AnswerHello, 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! QuestionHey, 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.

sub SaveSecurityEvents( strComputer, strFolder )

   set objWMIService = GetObject( "winmgmts:" _

   & "{impersonationLevel=impersonate,(Backup,security)}!\\.\root\cimv2" )

   strDateTime  = Year( Date )& "-" & Month( Date )& "-" _

                & Day(  Date )& "-" & Hour(  Time )

   strFileName     = strComputer & "-SecEvents-"  & strDateTime

   strPathFileName = strFolder & "\" & strFileName  & ".evt”

   set cobjLogFiles = objWMIService.ExecQuery _

   ( "Select * from Win32_NTEventLogFile where LogFileName='Security'" )

   for each objLogfile in cobjLogFiles

     objLogFile.BackupEventLog strPathFileName

   next

end sub

Stuck with Security Issues.

-- DS

 

Hey, Scripting Guy! AnswerHello, 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.

Well, this concludes another edition of Quick Hits Friday. Join me tomorrow for the Weekend Scripter when I will have a guest blogger.

I would love you to follow me on Twitter or Facebook. If you have any questions, send email to me at scripter@microsoft.com or post them on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

 

Ed Wilson, Microsoft Scripting Guy

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Detect 32-bit PowerShell

    1)64-bit OS run from $env:windir\system32\windowspowershell

    [IntPtr]::Size

    8

    2)$env:windir\SysWOW64\WindowsPowerShell\v1.0

    [IntPtr]::Size

    4

    $a = new-object -comobject MSScriptControl.ScriptControl

    $a.language = "vbscript"

    $a.addcode("function getInput() getInput = inputbox(`"Message box prompt`",`"Message Box Title`") end function" )

    $b = $a.eval("getInput")

    Is work fine ,if start from $env:windir\SysWOW64\WindowsPowerShell\v1.0

  • Hey Scripting Guy, now that a couple of years have passed, how do I put Powershell 3 on my Win 7 x64 box?

  • Is there an installation of 1.0 for windows 7? I need this because my company is using 1.0 still on their servers and it may cause an incompatibility problem.

  • hey how 2 install window 8

  • hey how 2 install window 8