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
  • Finding Logon Failures

    Whenever someone logs on with invalid credentials, there will be a log entry in the security log. Here is a function that can read these events from the security log (Admin privileges needed). It will then list all the invalid logons found in the log...
  • Finding Logged-On User

    There is a helpful console application called quser.exe which will tell you who is logged on to a machine. The executable returns plain text, but with the help of a little regular expression, this text can be converted to CSV and then imported into PowerShell...
  • Finding Logged-On User on Remote Machine

    In a previous tip we used quser.exe to find the currently logged-on user on the local machine. Here is now a function that also allows us to find the currently logged-on user on a remote machine. As an extra benefit, the returned information is appended...
  • 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...
  • 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...
  • 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...
  • 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...
  • 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...
  • 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...
  • 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...
  • 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...
  • Launching Applications with Alternate Credentials

    If you must run an application with a different identity, Start-Process offers the parameter -Credential. This would launch the Notepad editor using the context of user mydomain\myuser: Start-Process -FilePath notepad -Credential mydomain\myuser However...
  • Jagged Arrays

    This may not be for everyone: have a look at how you can create "jagged arrays". Here's a jagged array which really is a nested array: PS > $array = 1 , 2 , 3 , ( 1 , ( ' a ' , ' b ' ) , 3 ) , 5 It has five elements, and...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.