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 Built-In Administrators Group

    Using System User or group names like 'Administrators' in scripts may not always be a good idea because they are localized and may not work on machines that use a different UI language. Here is a rather long one-liner that always returns the name...
  • Using Advanced Breakpoints

    PowerShell supports dynamic breakpoints. They trigger when certain requirements are met. Like regular breakpoints, they all require that your script has been saved to a file. This line will set a breakpoint for script c:\test\script.ps1 that always triggers...
  • Matching Stars

    Asterisk serve as a wildcard, so how would you check for the presence of an asterisk? In a previous tip we used regular expressions for this, but there is an even easier way: PS > ' Test* ' . Contains ( ' * ' ) ReTweet this Tip!
  • Debugging PowerShell Scripts

    In PowerShell ISE, there are little-known built-in debugging features. Provided you have saved your script to a file, you can press F9 to set breakpoints, press F5 to run your script and then have it halt at any breakpoint it hits. Press F11 to step from...
  • Stopping Services Remotely

    Stop-Service cannot stop services remotely. One easy way of doing so is Set-Service: Set-Service -Name Spooler -Status "Stopped" -ComputerName targetcomputer However, unlike Stop-Service, Set-Service has no -Force parameter, so you cannot stop...
  • Easier ForEach/Where-Object in PSv3

    In the upcoming PowerShell v3 which you can already download as a Beta version, using Where-Object and ForEach-Object becomes a lot simpler. No longer do you need a script block and code. This, for example, is all you need to find files larger than 1MB...
  • Lunch Time Alert

    Here's a fun prompt function that turns your input prompt into a short prompt and displays the current path in your PowerShell window title bar. In addition, it has a lunch count down, displaying the minutes to go. Three minutes before lunch time...
  • Finding Files Owned by a User

    Here's a simple filter that will show only those files and folders that a specific user is owner of: filter Get-Owner ( $Account = "$env:UserDomain\$env:USerName" ) { if (( Get-ACL $_ . Fullname ) . Owner -like $Account ) { $_ } } It is...
  • Am I Privileged?

    There are numerous ways to find out if a script runs elevated. Here's a pretty simple approach: PS > ( whoami /all | Select-String S - 1 - 16 - 12288 ) -ne $null ReTweet this Tip!
  • Checking User Privileges

    whoami.exe is a useful little tool that ships with Windows 7/Server 2008 R2, and it becomes even more useful when you instruct it to output its result in CSV format. PowerShell can pick up CSV data and turn it into rich objects: PS > whoami /ALL /FO...
  • Resolving Paths

    Paths can be relative, such as ". \file.txt". To resolve such a path and display its full path, you could use Resolve-Path: PS > Resolve-Path .\file.txt Unfortunately, though, Resolve-Path expects the file to really exist, so you cannot use...
  • Synchronizing Current Folder

    PowerShell allows its own current path to differ from what Windows thinks is the current path: [ IO.Path ] :: GetFullPath ( ' . ' ) cd $env:windir Get-Location [ IO.Path ] :: GetFullPath ( ' . ' ) So, whenever you want to use one of the...
  • Check PowerShell Speed

    To find out how much time a particular cmdlet or command takes, here's a handy little stopwatch that you can use: function Test { $codetext = $Args -join ' ' $codetext = $ExecutionContext . InvokeCommand . ExpandString ( $codetext ) $code...
  • Running a Script Block with Parameters

    Maybe you want to design a script that takes code as user input. How would you run that submitted piece of code and pass parameters to it? To run a submitted script block, use Invoke-Command. This cmdlet can run script blocks locally and remote, and it...
  • Pinning PowerShell ISE

    The integrated PowerShell ISE editor has its own icon and can be pinned to the Windows 7 taskbar, just like PowerShell. Try this: Open PowerShell, and launch ise: PS > ise (If ISE does not start, you may be working on a server. ISE is not installed...
« First ... < Previous 58 59 60 61 62 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.