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
  • 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...
  • 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...
  • Weird Text Formatting (and what to do about it)

    Check out this code and try to find the problem: $desc = Get-Process -Id $pid | Select-Object -Property Description "PowerShell process description: $desc" This code gets the PowerShell host process and reads the process description, then outputs...
  • Using Encrypting File System (EFS) to Protect Passwords

    If you absolutely need to hardcode passwords and other secrets into your scripts (which you should avoid for obvious reasons), then you might still be safe when you encrypt the script with the EFS (Encrypting File System). Encrypted scripts can only be...
  • Logging Script Runtime

    If you'd like to monitor how long a script takes to run, you could use Measure-Command, but this cmdlet is for diagnostic purposes only and omits any script output. Another approach just takes two snapshots and at the end, calculates the time difference...
  • Converting Ticks into Real Date

    Internally, Active Directory uses ticks (100 nanosecond units since 1601) to represent date and time. It has been hard in the past to convert these huge numbers into human readable date and time. Here is a much easier way: [ DateTime ] :: FromFileTime...
  • Tag Your Objects with Additional Information

    There may be the need to add additional information to command results. Maybe you get data from different machines and want to keep a reference where the data came from. Or, you want to add a date so you know when the data was created. Tagging objects...
  • Finding Events around A Date

    Often, you might want to browse all system events around a given date. Let's say a machine crashed at 08:47, and you'd like to see all events +/− 2 minutes around that time. Here is a script that does It for you: $deltaminutes = 2 $delta...
  • Getting Group Membership - Fast

    If you need to find out the Active Directory groups your user account is in, typically you would query the Active Directory, and you would have to find the nested group memberships as well. Here is a technique that gets you your own group memberships...
  • Download PowerShell Language Specification

    All PowerShell Versions With PowerShell, it is really easy to download files from the Internet. Here is the code that downloads the PowerShell language specification--a great Word document full of PowerShell gems and internals--automatically to your machine...
  • Using the OpenFile Dialog

    PowerShell 3.0 and newer Here’s a quick function that works both in the ISE editor and the PowerShell console in PowerShell 3.0 and above): Show-OpenFileDialog. function Show-OpenFileDialog { param ( $StartFolder = [ Environment ] :: GetFolderPath...
  • Countdown Hours

    All PowerShell Versions Whether it is a birthday or an important game, you may want PowerShell to tell you just how many hours it is till the event starts. Here is how: $result = New-TimeSpan -End ' 2014-12-25 06:45:00 ' $hours = [ Int ] $result...
  • Correcting PowerShell Paths

    All PowerShell versions Occasionally, you might stumble across strange path formats like this one: Microsoft.PowerShell.Core \ FileSystem :: C:\windows\explorer.exe This is a full PowerShell path name which includes the module name and provider name that...
  • Finding Working Days

    To find all working days in a given month, here is a neat little one-liner: $month = 7 1 . .31 | ForEach-Object { Get-Date -Day $_ -Month $month } | Where-Object { $_ . DayOfWeek -gt 0 -and $_ . DayOfWeek -lt 6 } Simply assign the month to $month (the...
  • Reading Registry Values with Type

    All PowerShell Versions Reading all registry values is simple when you do not need the data type: simply use Get-ItemProperty: Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run If you do need the data type, a little more effort...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.