Idera nSoftware Compellent

Power Tips

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
  • Using String Functions

    PowerShell uses .NET objects everywhere. Anything is represented as .NET object, and .NET objects come with useful built-in methods. However, for string manipulation you do not need to look for sophisticated external commands as they are built right into...
  • Which PowerShell Version Am I Running

    As PowerShell v.2 becomes more common , you may want to check which PowerShell version a machine is running. Use this to differentiate between v.1 and higher versions from within PowerShell: $isV2 = test-path variable:\psversiontable Check this registry...
  • Multidimensional Arrays

    PowerShell supports two types of multi-dimensional arrays: jagged arrays and true multidimensional arrays. Jagged arrays are normal PowerShell arrays that store arrays as elements. This is very cost-effective storage because dimensions can be of different...
  • Checking File and Folder Permissions

    Get-Acl is a convenient Cmdlet to expose NTFS file and folder settings. For example, to get a list of ownerships for a folder content, do this: Dir | Get-Acl To find out which "Identities" (Users or groups) have specific permissions granted...
  • Finding the Current User

    Should you try and use PowerShell as a log-on script, you may want to know who is actually running the script to access user specific folders or settings. The .NET Environment class can tell you who is running a script. [ Environment ]:: UserDomainName...
  • Outputting HTML Reports

    PowerShell can export results as HTML. Simply pipe the results to ConvertTo-HTML and save the result in a file. When you do that, it is wise to use Select-Object to first limit the object properties to only those you want to see in your report, otherwise...
  • Sorting Arrays

    Let's assume you have an array of items which you would like to sort. Here is the PowerShell way: $array = 1,5,32,5,7 $array | Sort-Object $array = "Hello" , "World" , "Test" , "A" , "Z" $array | Sort...
  • Returning Exit Code from Script

    When running a PowerShell script, you may want to return a numeric exit code to the caller to indicate failure or success. You should use the "exit" statement to return whatever numeric exit code you want. The following line in a script would...
  • Encrypting PowerShell Scripts

    Sometimes, you may want to hide the code of your PowerShell script in order to protect passwords contained within the code. One way to safely encrypt PowerShell script is by converting it into a secure string. You must first create a sample script you...
  • Accessing Internet Explorer

    Accessing Internet Explorer can be useful for obtaining Web content. The usual approach uses a COM object called InternetExplorer.Application like this: $ie = New-Object -comObject InternetExplorer.Application $ie . visible = $true $ie . navigate ( 'http...
  • Manipulating Arrays Effectively

    While you can add and remove array elements with PowerShell arrays, this is an expensive operation and not recommended with large numbers of elements. Instead, use a .NET ArrayList if you need to dynamically expand and shrink an array at runtime: $array...
  • Ping and Range Ping

    In PowerShell, you can access .NET methods directly so it is easy to add a ping functionality: $object = New-Object system.Net.NetworkInformation.Ping $object . Send ( '127.0.0.1' ) You can wrap it as function to get even more out of this: function...
  • Calling VBScript From PowerShell

    Sometimes, you may have an existing VBScript that already does just what you want. You can easily incorporate any VBScript into PowerShell because PowerShell can call just about anything that is executable, including VBScript. The tricky part is that...
  • Trap and Try/Catch

    Trap, which has been around since PowerShell v.1, is designed to catch errors and works like this: trap { Write-Host -foregroundcolor Yellow ` "Something terrible happened: $($_.Exception.Message)" ; ` continue } & { dir nonexistent: -ErrorAction...
  • Create Text Reports with Format-Table

    Format-Table is a great cmdlet to output formatted data. Sometimes, you may just be interested in the raw table data. You can simply hide the column headers using -hideTableHeaders. Let's say you need a report of all the different file types in a...
1 2 3 4 5 Next > ... Last »
Copyright 2010 PowerShell.com. All rights reserved.