Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus


13 Free SQL Tools from Idera


Free Ebook: Mastering Powershell

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
  • Showing MsgBox

    Ever wanted to display a dialog box from PowerShell rather than spitting out console text? Then try this function: function Show-MsgBox { param ( [ Parameter ( Mandatory = $true )] [ String ] $Text , [ String ] $Title = ' Message ' , [ String...
  • ASCII Table

    Here’s a simple way of creating an ASCII table through type casting: 32 . .255 | ForEach-Object { ' Code {0} equals character {1} ' -f $_ , [ Char ] $_ } Likewise, to get a list of letters, try this: PS > [ Char []]( 65 . .90 ) A B (...
  • Pipeline Used Or Not?

    Sometimes you may want to know if your function received parameters over the pipeline or direct. Here is a way to find out: function test { [ CmdletBinding ( DefaultParameterSetName = ' NonPipeline ' )] param ( [ Parameter ( ValueFromPipeline...
  • Using Background Jobs to Speed Up Things

    PowerShell is single-threaded and can only do one thing at a time, but by using background jobs, you can spawn multiple PowerShell instances and work simultaneously. Then, you can synchronize them to continue when they all are done: # starting different...
  • Validate IP Addresses

    You can use regular expressions and the –match operator to validate user input. Here’s a loop that keeps asking until the user enters a valid IP address: $pattern = ' ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4]...
  • Converting UNIX Time

    Surprisingly, when you read some values from the Windows Registry, they do not seem to be in a readable format: $key = ' HKLM:\Software\Microsoft\Windows NT\CurrentVersion ' Get-ItemProperty $key | Select-Object -ExpandProperty InstallDate The...
  • Adding Support For –WhatIf and -Confirm

    Ever wanted to support the risk mitigation parameters –WhatIf and –Confirm in your functions, too? Here’s a code template that you can use to play and see how this works. It’s just a few lines of code: function Check-RiskMitigation...
  • Finding Disk Controller Errors

    This line will analyze your system event log for disk controller errors: PS > Get-EventLog -LogName System -InstanceId 3221487627 -ea 0 | ForEach-Object { $_ . ReplacementStrings [ 0 ] } | Group-Object -NoElement | Sort-Object Count -Descending Count...
  • Adding More Fonts to PowerShell Console

    Tired of using the boring default fonts in PowerShell? There are more monospaced fonts on your system. You just need to allow the console to use them. Here’s how: $key = ' HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont...
  • Reading Registry Values with Powershell

    In a previous tip we presented the functions New-RegKey and Set-RegistryValue to you which made creating registry keys and values very easy. Here is the missing Get-RegistryValue function which again is very easy to use to check the value of any registry...
  • Creating Registry Values

    In a previous tip we introduced the new function New-RegKey that could create one or more registry keys. Here is a function that creates registry values. It uses New-RegKey internally if the key you specify does not yet exist, so make sure you include...
  • Creating Registry Keys

    With this new function, it is simple to create new registry keys (including missing parent keys) in all registry hives. All you need are proper permissions: function New-RegKey { param ( $key ) $key = $key -replace ' : ' , '' $parts =...
  • Listing Domains in Forest

    Here is a function that lists all the domains in your forest: function Get - Domain { $Root = [ ADSI ] "LDAP://RootDSE" try { $oForestConfig = $Root . Get ( "configurationNamingContext" ) } catch { Write-Warning ' You are currently...
  • Turning On Standby-Mode

    To programmatically enter standby mode, you can use native .NET code like this: function Invoke-Standby { Add-Type -AssemblyName System.Windows.Forms [ System.Windows.Forms.Application ] :: SetSuspendState ( 0 , 0 , 0 ) | Out-Null } ReTweet this Tip!
  • Correctly Returning Exit Codes

    When you launch a PowerShell script from outside PowerShell, you may want to return an exit code to the caller so that the caller knows if your script ran ok. You can send back an exit code by using the statement exit xy where “xy” is a numeric...
« First ... < Previous 59 60 61 62 63 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.