October 2012 - Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

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
  • New Operators in PowerShell v3

    There are four new operators in PowerShell v3: -shl: shifts bits to the left -shr: shifts bits to right and preserves sign for signed values -in: works like -contains, operand order is reversed -notin: works like -notcontains, operand order is reversed...
  • Validation Attributes On Variables

    In PowerShell v2, function parameters could be decorated with validation attributes. In PowerShell v3, these attributes can now also be applied to plain variables, ensuring for example that they keep a certain range, thus producing more robust code: PS...
  • Line Breaks After "." and "::"

    In PowerShell v3 language syntax, it is finally allowed to have line breaks after "." and "::". These symbols are used to access dynamic and static object properties. So with PowerShell v3, concatenating such statements no longer necessarily...
  • Executing Code Locally and Remotely Using Local Variables

    Here is a piece of code that illustrates some of the challenges when writing remotable code: function Get - Log ( $LogName = ' System ' , $ComputerName = $env:computername ) { $code = { Get-EventLog -LogName $LogName -EntryType Error -Newest 5...
  • Using Local Variables Remotely

    If you want to send a script block to a remote computer, it is important to understand that the script block is evaluated on the remote computer. So all local variables are null: PS > $Path = ' C:\test ' PS > $scriptblock = { "Variable...
  • Firewall Problems When Enabling Remoting

    Enabling PowerShell Remoting is a simple thing: open an elevated PowerShell console and type: PS > Enable-PSRemoting -Force There are two types of exceptions you may encounter. One is complaining about public network adapters. If that's the case...
  • $PSItem in PowerShell v3

    In PowerShell, the variable "$_" has special importance. It works like a placeholder in scenarios like this one: PS > Get-ChildItem $env:windir | Where-Object { $_ . Length -gt 1 MB } In PowerShell v3, there is an alias for the cryptic "...
  • Resetting Console Colors in Powershell

    If a console application or script has changed the console colors and you want to reset them to the default colors defined in your console properties, try this: PS > $host . ui . RawUI . ForegroundColor = ' Red ' Now, the foreground color is...
  • Using Closures

    Script blocks are dynamic by default, so variables in a script block will be evaluated each time the script block runs. By turning a script block in a "closure", it keeps the state of the variables. Here is an example: PS > $var = ' A...
  • Discovering Useful Console Commands

    There are plenty of useful console commands such as ipconfig, whoami, and systeminfo. Most of these commands hide inside the Windows folder. Here's a clever function that lists all available commands with a short description of what they do in a window...
  • Check Windows License Status

    In a previous tip we explained how you can use slmgr, a built-in VBScript, to check Windows licensing state. The core information used by this VBScript actually comes from WMI, so in PowerShell, you can directly access the raw licensing data like this...
  • Calling Native Commands Safely

    Sometimes it isn't easy to call a command-line tool with some arguments. The PowerShell parser may interfere, and your call may even return completely wrong information. For example, run this command both in a cmd.exe shell and in PowerShell: findstr...
  • Manage Windows License Keys

    To automatically manage Windows license keys, use slmgr which is a VBScript that you can call from PowerShell. Just make sure that cscript.exe is your default VBScript host. From an elevated PowerShell console, type this: wscript.exe // H : cscript Next...
  • Unzipping Files

    Unfortunately, there is no built-in cmdlet to unzip files. There are plenty of 3rd party tools, many of which are free. If you cannot use these tools, here's how native Windows components can unzip files, too. Note that this requires the built-in...
  • Downloading Files from Internet

    PowerShell v3 comes with a hugely useful new cmdlet called Invoke-WebRequest . You can use it to interact with websites which also includes downloading files. This will download the SysInternals suite of tools to your computer: $Source = ' http:/...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.