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
  • Shortening Text

    Let's assume you want to chop off some text at the end of a string. This is the traditional approach using string operations: $text = "Some text" $fromRight = 3 $text . Substring ( 0 , $text . Length - $fromRight ) A much more powerful way...
  • Avoid Using Redirection

    While you can still use the old redirection operator to write command output to a file, you should rather use PowerShell cmdlets instead. Here is why: #requires -Version 2 $OutPath = " $env:temp\report.txt " Get-EventLog -LogName System -EntryType...
  • Encode PowerShell Commands

    When you need to run code as a PowerShell command in a separate powershell.exe, it is not always safe to submit the code. Depending on from where you call powershell.exe, your code argument may get modified by parsers, or special characters inside your...
  • Define Multiline Text

    When you need to define multiline text, in PowerShell you typically use here-strings like this: $text = @" I am safe here I can even use "quotes" "@ $text | Out-GridView The important thing to note is that the delimiters include (invisible...
  • Current Script Path

    In PowerShell 1.0 and 2.0, you needed a lot of weird code to find out the current script location: # make sure the script is saved and NOT "Untitled"! $invocation = ( Get-Variable MyInvocation ) . Value $scriptPath = Split-Path $invocation ...
  • Discovering Dynamic Parameters

    In a previous tip we showed how you find cmdlets that expose dynamic parameters. Let's explore what the dynamic parameters are. The function Get-CmdletDynamicParameter returns a list of dynamic parameters and their default values: #requires -Version...
  • Finding Cmdlets with Dynamic Parameters

    Some cmdlets expose dynamic parameters. They are valid only in certain contexts. Get-ChildItem, for example, exposes -File and -Directory only when the current location is a file system path (and you are at least running PowerShell 3.0). To find all cmdlets...
  • Change ISE Zoom Level

    The PowerShell ISE sports a zoom slider at its lower right edge, and you can control this slider with PowerShell code. So you could set defaults for it in your $profile script: $psise . Options . Zoom = 120 Or, write some code to keep your colleagues...
  • Unzipping ZIP Files with any PowerShell Version

    If you do not have PowerShell 5.0 and .NET Framework 4.5 is not available, here is an approach to unzip ZIP files that uses the native Windows shell support. If you have installed custom ZIP file extensions for the explorer, this approach may not work...
  • Unzipping ZIP Files with PowerShell 3.0 and 4.0

    ZIP file support was introduced in PowerShell 5.0, but if you have installed the .NET Framework 4.5 and possibly want more control over the unzipping process, try this: #requires -Version 2 # .NET Framework 4.5 required! Add-Type -AssemblyName System...
  • Unzipping ZIP Files

    In PowerShell 5.0, there is a new cmdlet that can unzip ZIP files: #requires -Version 5 $Source = ' C:\somezipfile.zip ' $Destination = ' C:\somefolder ' $Overwrite = $true $ShowDestinationFolder = $true Expand-Archive -Path $Source -DestinationPath...
  • Finding Computers with PowerShell Remoting

    In a previous tip we showed how you can test the network port of a computer. When you have installed the free RSAT tools from Microsoft, you could query your Active Directory and get a list of all computer accounts, or all computer accounts in a given...
  • Testing a Network Port

    To see whether you can access a remote computer via a given network port, here is a test function called Test-Port; it takes a remote computer name (or IP address), and optionally a port number and timeout. The default port is 5985 which is used for PowerShell...
  • Finding Logged On Users

    In a previous tip we explained how you find the physically logged on user. In this tip you will see how you can list the current logon sessions, reporting all users who are currently logged on to a system. This includes users that are connected via RDP...
  • Find Physically Logged On User

    There can always be only one physically logged on user on a machine. The physically logged on user is the one sitting right at the machine. Here is a PowerShell function that reports the physically logged on person for a local or remote system. To access...
< Previous 1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.