PowerShell Team

Automating the world one-liner at a time…

Latest posts

Get-Process Piped to Dir
Sep 17, 2006
0
0

Get-Process Piped to Dir

PowerShell Team
PowerShell Team

Did you know that you can pipe the output of Get-Process into dir?  Don't believe it?  Let me prove it: PS> Get-Process wi*Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName-------  ------    -----      ----- -----   ------     -- -----------     95       4     1080       2892    32     0.30  ...

Useful DateTime functions – LibraryTime.ps1
Sep 17, 2006
0
0

Useful DateTime functions – LibraryTime.ps1

PowerShell Team
PowerShell Team

I was going to post a blog entries and realized that the example I wanted to give used some of my utility functions so I'll share them first.  I hope you find them interesting.  I put them in a file called LibraryTime.ps1 and dot source that during my login.  BTW  - everyone should adopt that pattern.  Files that contain functions meant to be dot sourced into another script should be called LibraryXXXX.ps1 function Measure-TimeSpan([TimeSpan]$Span, $Units=$Null){   switch ($Units)   {   "Weeks"        {[Int]($Span.TotalDays ...

The Wonders of Date Math using Windows PowerShell
Sep 17, 2006
0
0

The Wonders of Date Math using Windows PowerShell

PowerShell Team
PowerShell Team

Larry Hayden posted a query about dates at:http://techtasks.com/bookmarks/powershell/2006/09/interview-with-a-scripter-jeffrey-snover/ He has a script which gets all the Application Events that happened TODAY: ————————————————————$today = [DateTime]::Today$Events = Get-Eventlog -New 1024 Application | Where {$Today -le $_.TimeWritten}$Events |Group EntryType,Source |Format-Table Count,Name -Auto———————————————————— What Larry really wants is the Application Events that happend in the last 24 hours.  We'll Larry - you're in luck because PowerShell leverages the awesome .NET frameworks which support Date Math....

ErrorLevel equivalent
Sep 15, 2006
0
0

ErrorLevel equivalent

PowerShell Team
PowerShell Team

PSMDTAG:FAQ: ErrorLevel - what is the PowerShell equivalent? In Cmd.exe, %ErrorLevel% is a builtin variable which indicates the success or failure of the last executable run. In PowerShell, we support:     $?       Contains True if last operation succeeded and False otherwise.And     $LASTEXITCODE       Contains the exit code of the last Win32 executable execution. PS> 2+24PS> $?TruePS> 3/$nullAttempted to divide by zero.At line:1 char:3+ 3/$ <<<< nullPS> $?FalsePS>PS> ping localhost Pingin...

Draft – Creating Cmdlet Help
Sep 14, 2006
0
0

Draft – Creating Cmdlet Help

PowerShell Team
PowerShell Team

NOTE: This content is also included as an RTF attachment as well. Creating Cmdlet Help When creating your own cmdlet, you can also create Help content that Windows PowerShell can display using the Get-Help cmdlet. The Help content that describes your cmdlet can include a description of the cmdlet, the syntax used by your cmdlet, parameter descriptions, examples, and other related notes. Creating the Help XML file The name of the Help file must be in the following format: MySnapinAssemblyName.dll-Help.xml Example The following XML shows the major sections that are in t...

Windows PowerShell on TechNet Radio
Sep 12, 2006
0
0

Windows PowerShell on TechNet Radio

PowerShell Team
PowerShell Team

Tune in & Geek out at Technet Radio: http://www.microsoft.com/technet/community/tnradio/default.mspx There are a couple of PowerShell podcasts there: Drill down into Windows PowerShell: An interview with Jeffrey Snover Scripting with Windows PowerShell: An interview with Vivek Sharma and Mihai Jalobeanu Enjoy! Jeffrey Snover [MSFT]Windows PowerShell/Aspen ArchitectVisit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShellVisit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Controlling Internet Explorer object from PowerShell
Sep 10, 2006
1
0

Controlling Internet Explorer object from PowerShell

PowerShell Team
PowerShell Team

NOTE: The site must be in the Trusted Sites Zone for this script to work - James Brundage [MSFT] January 5th, 2009 The following example shows how to display all the processes in an IE window and highlight the ones with memory usage of greater than or equal to the specified value. $oIE=new-object -com internetexplorer.application$oIE.navigate2("About:blank")while ($oIE.busy) {    sleep -milliseconds 50}$oIE.visible=$true$procList=ps |select-object ProcessName,Handles,NPM,PM,WS,VM,CPU,Id |convertto-html $oDocBody=$oIE.document.documentelement.lastchild ; #populate the document.body$oDocBody.inn...

Thomas Lee on Monad (Windows PowerShell)
Sep 9, 2006
0
0

Thomas Lee on Monad (Windows PowerShell)

PowerShell Team
PowerShell Team

The site that has the Best of TECHED Boston also has the BEST of other shows as well.  I'm not sure when/where Thomas gave this talk but I just watched it and it is highly entertaining.  It's clear that Thomas has been in front of crowds a couple of (thousand) times.  For those of you that don't already know Thomas - he is a maniac (in a good way).  Find out for yourself at: http://www.microsoft.com/emea/itsshowtime/sessionh.aspx?videoid=277 Enjoy! Jeffrey Snover [MSFT]Windows PowerShell/Aspen ArchitectMicrosoft CorporationVisit the Windows PowerShell Team blog at: http://blogs.msdn.com/Power...

FREE Windows PowerShell Help Tool from Sapien
Sep 9, 2006
0
0

FREE Windows PowerShell Help Tool from Sapien

PowerShell Team
PowerShell Team

Command line help is great because it is always there when you need it.  That said, sometimes you want to have the help in one window while you experiement in the other.  You can always do that with 2 console windows but why would you do that when you can download Sapien's FREE Windows PowerShell help tool.  They have a download like in the text of their page describing Don Jones and Jeffrey Hicks PowerShell TFM book.  That's TFM as in RTFM.  clever. http://www.sapienpress.com/powershell.asp Enjoy! Jeffrey Snover [MSFT]Windows PowerShell/Aspen ArchitectMicrosoft CorporationVisit the...