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
  • Aborting the Pipeline

    If you know beforehand how many results you expect from a pipeline, you can use Select-Object to stop the upstream cmdlets. This can save a lot of time. This example tries to find the first instance of explorer.exe inside the Windows folder. Because of...
  • Passing Arrays to Pipeline

    If a function returns more than one value, PowerShell wraps them in an array. However, if you pass the results to another function inside a pipeline, the pipeline automatically "unwraps" the array and processes one array element at a time. If...
  • Free PowerShell Module for Admins

    One feedback we got on a previous tip directed us to "Carbon", a free PowerShell module crammed with useful PowerShell functions. One is Get-IPAddress which returns all IP addresses assigned to your computer. You can find more information about...
  • Converting CSV to Excel File

    PowerShell can easily create CSV files using Export-Csv, and if Microsoft Excel is installed on your system, PowerShell can then have Excel convert the CSV file to a native XLSX Excel file. Here is some sample code. It uses Get-Process to get some data...
  • Who is Accessing Network Resources?

    Provided you have Administrator privileges, you can use a simple WMI class to check whether someone is accessing your resources via the network: PS> Get-WmiObject -Class Win32_ServerConnection | Select-Object -Property ComputerName , ConnectionID ...
  • Disable Automatic Reboot After Update

    Are you tired of Windows unexpectedly rebooting, just because some newly installed updates required a reboot? Like most things, you can control the reboots via policy settings, and most policy settings are just registry keys. Here is a sample script that...
  • Removing Whitespace (and Line Breaks)

    You may know that each string object has a method called Trim() that trims away whitespace both from the beginning and end of a string: $text = ' Hello ' $text . Trim () A lesser known fact is that Trim() will also eat away leading and trailing...
  • Receiving Error Level from PowerShell Script

    Here is a quick script illustrating how a PowerShell script can send back a numeric status code to the caller: $exitcode = 123 $p = Start-Process -FilePath powershell -ArgumentList "-command get-process; exit $exitcode" -PassThru Wait-Process...
  • 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...
< Previous 1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.