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
  • Why "exit" can kill PowerShell

    Occasionally, there are misunderstandings how "exit" works. Take this example: function abc { ' Start ' exit 100 ' Done ' } abc When you run this script, the abc function is called, then aborted. You will see only "Start"...
  • Understanding break, continue, return, and exit

    Do you know off-hand what "break", "continue", "return", and "exit" do? These are powerful language constructs, and here is a test function to illustrate how different their effects are: ' Starting ' function...
  • Identifying Risky NTFS Permissions

    Here is a quick and easy way to find NTFS permissions that are potentially dangerous. The script tests all folders in $pathsToCheck and reports any security access control entry that grants access to one of the filesystem flags defined in $dangerousBitMask...
  • Get IP Address Geolocation

    Would you like to know where a public IP address is located? Provided you have Internet access, you can query one of the public information services. This example gets you the geolocation of an IP address. Make sure you replace the sample IP address with...
  • Get Current IP Address

    Here is a quick way to get all IP addresses assigned to your computer: #requires -Version 1 $ipaddress = [ System.Net.DNS ] :: GetHostByName ( $null ) Foreach ( $ip in $ipaddress . AddressList ) { $ip . IPAddressToString } If you replace $null with a...
  • Validating Domain Credentials

    To check credentials (username plus password) against your current domain, you can use this approach: #requires -Version 1 $username = ' test\user ' $password = ' topSecret ' $root = "LDAP://" + ([ ADSI ] "" ) . distinguishedName...
  • Safely Use UNC Paths

    Whenever you use UNC paths in PowerShell, your script may break. Since a UNC path has no drive letter, PowerShell looks at the current directory instead, and uses the PSProvider attached to the current directory. So if your current directory is not a...
  • Using Splatting

    With splatting, you can call cmdlets and programmatically control the parameters you submit. To do this, add the parameters and values to a hash table, then submit the hash table to the cmdlet. This works with any cmdlet. Here is an example: # classic...
  • Reading RSS Feeds

    RSS feeds can be read by using an XML object, however XML objects do not support proxies. Here is an example that uses Invoke-WebRequest to retrieve the RSS data via proxy (or directly if you omit the proxy parameters), then converts the results to XML...
  • Getting Registry Values and Value Types

    Get-ItemProperty can easily read registry values, but you do not get back any information about the registry value type. Get-ItemProperty -Path ' HKLM:\Software\Microsoft\Windows NT\CurrentVersion ' Here is an alternate approach that uses .NET...
  • Finding Information about TV Series

    PowerShell can query websites that deliver XML content, and here is an example on how to query a movie database. Simply adjust the name of the TV series you are interested in. Optionally, use the parameter for a proxy if you have no direct Internet access...
  • Comparing Folder Content

    To quickly compare folder content and find out files that exist only in one of two folders, try this example: $list1 = Get-ChildItem c:\Windows\system32 | Sort-Object -Property Name $list2 = Get-ChildItem \\ server12 \ c $\ windows \ system32 | Sort-Object...
  • Bulk Renaming Files

    Let's assume you have a folder full of picture files, and you'd like to standardize naming. Here is a script illustrating how you can do a bulk rename: $i = 0 Get-ChildItem -Path c:\pictures -Filter * . jpg | ForEach-Object { $extension = $_ ...
  • Encoded Passwords

    If you must put a credential object in your script, here is a way how you can convert a secure string into encrypted text: $password = Read-Host -Prompt ' Enter Password ' -AsSecureString $encrypted = $password | ConvertFrom-SecureString $encrypted...
  • Find All Active Drive Letters

    To quickly get a list of all drive letters in use, try this: #requires -Version 1 [ Environment ] :: GetLogicalDrives () The result is a list of all active drive letters: PS> C:\ D:\ E:\ F:\ G:\ ReTweet this Tip!
« First ... < Previous 2 3 4 5 6 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.