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
  • Finding Paths to Special Locations

    If you’d like to access any of the following special locations, then we have good news for you: PS C:\> [System.Enum]::GetNames([System.Environment+SpecialFolder]) Desktop Programs MyDocuments Personal Favorites Startup Recent SendTo StartMenu...
  • Copy Over PowerShell Remoting Sessions

    You can use PowerShell remoting to transfer files across a network – this is new in PowerShell 5.0. This can be useful in closed environments where you have no SMB file shares. It is not very efficient (and slow) though. Here is an example: # Create...
  • One-Liner Random Password Generator

    Check out this simple way of creating temporary passwords: -join ( ' abcdefghkmnrstuvwxyzABCDEFGHKLMNPRSTUVWXYZ23456789$%&*# ' . ToCharArray () | Get-Random -Count 8 ) You can easily vary the password length: change the number for -Count to...
  • Harvesting Reboot Time from EventLog

    In the previous tip we illustrated how you can ask WMI for the last reboot time of a machine. A more robust way is to query the Windows event logs. Here is how: # get the latest reboot event from the System event log $e = Get-EventLog System -Source Microsoft...
  • Last Bootup Time with Get-CimInstance

    These days, computers hibernate or go into standby but do not really reboot that often anymore. To find out when your computer rebooted the last time, try this line in PowerShell 3.0 or better: Get-CimInstance -Class Win32_OperatingSystem | Select-Object...
  • Extracting Text Information

    Tracert.exe tells you the hops your data packages need to take to get to a given host. Here is an example: PS C:\> tracert www.microsoft.com Tracing route to e10088.dspb.akamaiedge.net [2.16.194.227] over a maximum of 30 hops: 1 8 ms 8 ms 9 ms 1st...
  • Bulk-Convert to String

    Sometimes, commands and methods do not return exactly what you are after. If you, for example, wanted to get the assigned IP addresses for a hostname, you could try this: [ System.Net.DNS ] :: GetHostByName ( ' microsoft.com ' ) . AddressList...
  • Create Local Admin Accounts

    There is no module available for all PowerShell versions that allows to administer local user accounts. Here is a chunk of sample code that illustrates how you nevertheless can automate local account management. The code creates a new local Administrator...
  • Loops and Arrays (and some surprises)

    Frequently, loops are used to retrieve (or generate) data, then save it to a variable. There can be tremendous performance differences though. To generate 10.000 random numbers, for example, you might look into something like this: $numbers = @ () for...
  • Finding Top 3 (of anything)

    Ever wanted to know who are the three worst sources for errors in your System event log? Here is a simple approach that yields the source names with the most errors: Get-EventLog -LogName System -EntryType Error | Group-Object -Property Source | Sort...
  • Converting Fixed-Width Text Data

    PowerShell can turn fixed-width tabular data easily into rich objects. First, define the column widths. Then, have PowerShell inject a delimiter at these positions. Finally, ConvertFrom-Csv can split the text lines and turn the text into rich objects...
  • Exclude Properties

    With Select-Object, you typically include the object properties you want to receive. You can do it the other way around, too, though. Here is an example that includes all properties except some unwanted ones: #requires -Version 2 # get the latest 20 errors...
  • Creating Temporary Passwords

    A good temporary password should be complex, yet unambiguous. So it should contain a mixture of upper and lower case plus special characters, but it should avoid conflicting characters such as "o", "O", and "0". Here is sample...
  • Beeping PowerShell

    Your colleague went to lunch again without properly locking his computer? Then this is your chance to run this code on his PowerShell: $powershell = [ PowerShell ] :: Create () $code = { while ( $true ) { Start-Sleep -Milliseconds 3000 [ Console ] ::...
  • Controlling Return Values

    In the previous tip we explained why functions can have multiple return values, and that anything you leave behind will be added to the return values. If you'd like PowerShell to behave like a classic scripting language, and exclusively set the return...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.