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
  • 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...
  • Safely Running PowerShell Scripts

    If you want to run a PowerShell script from outside PowerShell, for example from within a batch file, you probably know that you need to prepend powershell.exe to the script path. But that is not enough. Always add these three parameters to launch your...
  • Adding PowerShell Goodies to Server 2008 R2

    Windows Server 2008 R2 comes with a PowerShell module called ServerManager which in turn allows you to add additional features to the server. Here’s a list of features you might want to install to get the maximum PowerShell experience: First, load...
  • Recording Audio Text Files

    Did you know that PowerShell can record audio messages? All you need is some text. You can then turn the text into spoken language, convert it to a WAV file and play it back or send it to someone. Here’s how: $Path = " $env:temp\file.wav "...
  • Enter Hibernation Mode

    Maybe you are running lengthy tasks at night. Sometimes you may want to place the machine into hibernation once your script is done. Here’s a function that uses a console application to enter hibernation mode: function Invoke-Hibernate { shutdown...
« First ... < Previous 58 59 60 61 62 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.