by Viper
30. January 2009 10:35
I was looking at Microsoft documentation on how to register custom Cmdlets to install one of my Cmdlets. I realized that I made some mistake in the implementation. So I had to uninstall Cmdlet from shell. You will follow the same instructions from documentation with one change. You can specify /u parameter to InstallUtil to uninstall the assembly. So the command will look following:
PS> set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil
PS> installutil /u SelectStrCommandSample.dll
Microsoft (R) .NET Framework Installation utility Version 2.0.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
…
The uninstall has completed.
by Viper
30. January 2009 02:59
If you want to install Pwershell V2.0, one of the requirements is to uninstall previous versions of Powershell. If you don't do that, while installing V2.0, you will get message about uninstalling it. And the message does say to use Add/Remove Programs to uninstall it. So I went to Add/Remove Programs panel and could not find it there. That was frustrating. So I decicded to do some manual search about this installed program. All programs installed on Windows (if done right) have a registry entry at HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall location. If you search on that node for Powershell you will find a key for KB926139-2. Look at value for ParentDisplayName. It points to Windows XP - Software Updates. When we goto Add/Remove Programs control panel, the check box for Show Updates is usually not selected by default. So check that box and you should see all updates. Now you will find Powershell installation under Windows XP- Software Updates (depending on operating system you are using. You can now uninstall it from here. Following screen shot shows registry entry from my machine.

|
|
|
by Viper
29. January 2009 15:37
A lot of time you want to filter your results from Get-* command in Powershell. One way to do will be to pass the results from Get-* command through two where-object pipe lines. Or you can take advantage of logical operators to combine more than one filter in one where-object FilterScript. For example I wanted to get list of processes on my server that are using more than 2MB of memory or have more than 400 file handles open. Following command shows how two filters were combined.
get-process | where {($_.WorkingSet -gt 1024*2048) -or ($_.HandleCount -gt 400)}
Following is list of logical operators that are available in PowerShell.
| Logical Operator | Meaning |
| -and | Logical and; true if both sides are true |
| -or | Logical or; true if either side is true |
| -not | Logical not; reverses true and false |
| ! | Logical not; reverses true and false |
by Viper
29. January 2009 10:24
I was working on some automation script and somebody asked me whats the day of the week on a certain date. I was like lets see if i can do it without opening up calendar. So i decided to play around with get-date command in Powershell. And there it was, some fun with the command to try different things. Following are some commands that you can try yourself.
How to get day of week
get-date -format dddd
How to get day of week for any date
get-date -format dddd -Year 2010 -Month 2 -Day 28
Notice use of Year, Month and Date parameters. If you omit one of these parameters, then command will use today's component of that parameter.