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
  • Use $PSScriptRoot to Load Resources

    Beginning in PowerShell 3.0, there is a new automatic variable available called $PSScriptRoot. This variable previously was only available within modules. It always points to the folder the current script is located in (so it only starts to be useful...
  • Signing VBScript Files with PowerShell

    You probably know that Set-AuthenticodeSignature can be used to digitally sign PowerShell scripts. But did you know that this cmdlet can sign anything that This piece of code would load a digital certificate from a PFX file, then scan your home folders...
  • Correctly Filtering DateTime

    When you use Where-Object to filter information by date or time, this works actually very well--provided you use the correct filtering format. Do not use the format found in the results. To specify a date and or time, always use the culture-neutral management...
  • Use Fresh Testing Environment in PowerShell ISE

    When you develop PowerShell scripts in the PowerShell ISE editor, you should run the final tests in a clean environment, making sure that no leftover variables or functions from previous runs interfere. The easiest way to create a completely fresh testing...
  • Importing Multiple Certificates from PFX Files

    Get-PfxCertificate can import digital certificates from a PFX file. However, it can only retrieve one certificate. So if your PFX file contains more than one certificate, you cannot use this cmdlet to get the others. To import multiple certificates from...
  • Using Fully Qualified Names in Remoting

    When you try PowerShell Remoting, you may run into connection errors just because your machine name was not fully qualified. Kerberos authentication may or may not needs this, depending on your DNS configuration. So maybe you get errors when you try and...
  • Ensuring Backward Compatibility

    Let's assume you have created this function: function Test-Function { param ( [ Parameter ( Mandatory = $true )] $ServerPath ) "You selected $ServerPath" } It works fine, but half a year later in a code review, your boss wants you to use...
  • Importing Certificates from PFX Files

    You can use Get-PfxCertificate to load digital certificates from PFX files, and then use the certificate to sign script files, for example: $pfxpath = ' C:\PathToPfxFile\testcert.pfx ' $cert = Get-PfxCertificate -FilePath $pfxpath $cert Get-ChildItem...
  • Reading StringExpand Registry Values

    When you read a Registry value of type StringExpand, it will always automatically expand any environment variables contained in the text. This example will read the system device path from your Registry: $path = ' HKLM:\SOFTWARE\Microsoft\Windows...
  • Setting (And Deleting) Environment Variables

    PowerShell can read environment variables easily. This returns the current windows folder: $env:windir However, if you want to make permanent changes to user or machine environment variables, you need to access .NET functionality. Here is a simple function...
  • Mandatory Parameter with a Dialog

    Typically, when you mark a function parameter as "mandatory", PowerShell will prompt the user when the user omits the parameter: function Get-Something { param ( [ Parameter ( Mandatory = $true )] $Path ) "You entered $Path" } The...
  • Using Comma as Decimal Delimiter

    You may not be aware of this, but PowerShell uses a different decimal delimiter for input and output - which may cause confusions to script users. When you enter information, PowerShell expects culture-neutral format (using "." as decimal delimiter...
  • Testing for Valid Date

    If you need to test whether some information resembles a valid date format, here is a test function: function Test-Date { param ( [ Parameter ( Mandatory = $true ] $Date ) (( $Date -as [ DateTime ]) -ne $null ) } It uses the -as operator to try and convert...
  • Speaking English and German (and Spanish, and you name it)

    Windows 8 is the first operating system that comes with fully localized text-to-speech engines. So you can now have PowerShell speak (and curse) in your mother tongue. At the same time, there is always an English engine, so your computer is now bilingual...
  • Multiple Assignments in One Line

    When you assign something to a variable, you can enclose the expression in braces. This will also output the data. Have a look: $a = Get-Service ( $a = Get-Service ) See the difference? The second line will not only assign the results from Get-Service...
« First ... < Previous 2 3 4 5 6 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.