October 2011 - Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

Welcome to the archive of tips delivered through Tobias' Tip of the Day RSS Feed and Your Power Tip of the Day email. Subscribe in the sidebar to get the latest tips!

Sort by: Most Recent | Most Viewed | Most Commented
  • Creating Intelligent Variables

    To create variables that calculate their content each time they are accessed, use access-triggered variable breakpoints. This line, for example, creates a global variable called $today, and each time you access its content, it returns the current time...
  • Setting Breakpoints in PowerShell Scripts

    Most sophisticated PowerShell editors have built-in debugging support. PowerShell can handle breakpoints natively, too, though. To make PowerShell stop execution in a script, here is how: Set-PSBreakpoint -Script c:\scripts\somescript.ps1 -Line 4 Next...
  • PowerShell Script Security Auditing

    When you digitally sign scripts, you can easily tell whether a script was manipulated or comes from an untrusted source. Here is a function that can find all PowerShell scripts on a drive or in a folder and lists security issues: function Test - PSScript...
  • Re-Encoding ISE-Scripts

    When you save scripts with the PowerShell ISE script editor, they are saved with the rather unusual "Big Endian Unicode" encoding. That's bad because this is the only encoding that you cannot digitally sign. In PowerShell V3, this has been...
  • Digitally Signing PowerShell Scripts

    In a previous tip, we illustrated how you access a code signing certificate that was installed on your computer. With such a certificate, you can sign one or all PowerShell scripts in a folder. Here is how you sign all PowerShell scripts in folder c:...
  • Finding Code Signing Certificates

    To digitally sign PowerShell scripts, you need a certificate with the purpose "CodeSigning". Here is how you find out which code signing certificates are available to you - if any: dir cert:\CurrentUser\my -CodeSigningCert If this line does...
  • How Large Are My Folders?

    To find out the total size of all subfolders in a directory, try this function: function Get - FolderSize ( $Path = $home ) { $code = { ( ' {0:0.0} MB ' -f ( $this / 1 MB )) } Get-ChildItem -Path $Path | Where-Object { $_ . Length -eq $null }...
  • HTML-Scraping with RegEx

    To scrape valuable information from websites with PowerShell you can download the HTML code and then use regular expressions to extract what you are after. That's not hard. Here is a sample: $webclient = New-Object System.Net.WebClient $html = $webclient...
  • Finding Multiple RegEx Patterns

    PowerShell comes with great support for regular expressions but the -match operator can only find the first occurrence of a pattern. To find all occurrences, you can use the .NET RegEx type. Here is a sample: $text = ' multiple emails like tobias...
  • Creating Pipeline Filters

    In a previous tip, we illustrated how a function can run inside a PowerShell pipeline. That's an excellent way to create filters. Here is a filter that will only display processes that have a "MainWindowTitle" text, thus filtering all running...
  • Using Functions inside the Pipeline

    Code inside PowerShell functions always is placed in the begin, process, or end block. You may not have noticed this because when you don't do this yourself, PowerShell places your entire function code inside an end block. When you try and run a function...
  • Forget the "Finally"-Block

    When you handle errors using try/catch/finally, you may wonder what the finally block is for. Here is a demo: try { dir nonexisting:\ -ErrorAction Stop } catch { "Error Occured: $_" } finally { ' Doing Cleanup ' } Whenever a non-terminating...
  • Understanding and Handling Terminating Errors

    To suppress errors in a cmdlet, you can use the common parameter -ErrorAction SilentlyContinue. Here is a sample: Get-WmiObject Win32_BIOS -ComputerName localhost , offline , 127.0.0.1 -ErrorAction SilentlyContinue | Select-Object __Server , Manufacturer...
  • Use "E" in Numbers

    To quickly define large integers, use the keyword "E" inside your number: PS > 64E6 64000000 ReTweet this Tip! http://bit.ly/pGRrMP
  • Executing PowerShell Commands with Full Privileges

    If a script needs to run only particular commands with full Administrator privileges, you can run those in a separate elevated shell. $code = "md $env:windir\newfolder | Out-Null" if (( Test-Path $env:windir\newfolder) -eq $false ) { Start-Process...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.