September 2011 - Power Tips

Share |

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
  • Adding Members to Local Group

    To manage local groups, you can think about using net.exe. It may be much easier than using COM interfaces. The next line will add a local user account to the local Administrators group: net localgroup Administrators Tobias /ADD This functionality may...
  • Office365 Cmdlets

    Office365 comes with a complete set of PowerShell cmdlets. To review the cmdlets and what you can do with them, visit this URL: ReTweet this Tip!
  • Filtering Files or Folders

    To filter folder content by file or folder, check whether the Length property is present. It is present for files and missing in folders: Dir $env:windir | Where-Object { $_ . Length -eq $null } Dir $env:windir | Where-Object { $_ . Length -ne $null ...
  • Extracting Icons

    To extract an icon from a file, use .NET Framework methods. Here is a sample that extracts all icons from all exe files in your Windows folder (or one of its subfolders) and puts them into a separate folder: [ System.Reflection.Assembly ] :: LoadWithPartialName...
  • Displaying Balloon Tip

    Let's assume your script wants to share status information via a balloon message in the system tray area. Here is a sample: [ system.Reflection.Assembly ] :: LoadWithPartialName ( ' System.Windows.Forms ' ) | Out-Null $balloon = New-Object...
  • Listing Windows Updates

    There is a not widely known COM object that you can use to list all the installed Windows Updates on a machine. Here is the code: $Session = New-Object -ComObject Microsoft.Update.Session $Searcher = $Session . CreateUpdateSearcher () $HistoryCount =...
  • Controlling PSComputerName in Remoting Data

    Whenever you use Invoke-Command to remotely execute code, you will notice that PowerShell automatically adds the column PSComputerName to your results. That's great because when you run Invoke-Command against more than one computer, you want to still...
  • Determine Functions Pipeline Position

    Assume your function wanted to know whether it is the last element in a pipeline or operating in the middle of it. Here is a way for a function to determine its current pipeline position: function test { param ( [ Parameter ( ValueFromPipeline = $true...
  • Clean your TEMP folder!

    When disk space gets low, you may want to clean up your temporary folder. The code deletes all files that are older than 30 days to make sure you're not dumping anything that's still needed: $cutoff = ( Get-Date ) - ( New-TimeSpan -Days 30 ) ...
  • Forwarding Selected Parameters

    In a previous tip you learned how you can forward function parameters to cmdlets. But what if you just want to forward some of the parameters? Here is a sample: function Get - BIOS ( $ComputerName , $Credential , [ switch ] $Verbose ) { $a = $global:psboundparameters...
  • Saving History to Script

    PowerShell is all about trial and error, and when you want to save your interactive input to a script file, this is how it could be done: Get-History -Count $MaximumHistoryCount | ForEach-Object { $_ . CommandLine | Out-File $env:temp\myscript.ps1 -Append...
  • Creating Local Admins

    Here is a piece of code that will create a local user account and put it into the local Administrators group: $computername = $env:computername # place computername here for remote access $username = ' AdminAccount1 ' $password = ' topSecret...
  • Creating Local Admins (Part 2)

    In a previous tip, we showed you how to create a new local admin account using ADSI. On Windows 7 and Server 2008, it is much easier to use net.exe instead: net user AdminAccount1 /ADD net localgroup Administrators AdminAccount1 /ADD ReTweet this Tip...
  • Enabling Remote WMI and DCOM

    Many cmdlets have a built-in -ComputerName parameter that will allow for remote access without using the new PowerShell remoting. For this to work, your firewall will need to be adjusted on the target machine: In addition, some cmdlets (like Get-Service...
  • How Long Has Shell Been Running?

    To find out how long your PowerShell session has been running, try this code snippet: (((( Get-Date ) - ( Get-Process -id $pid ) . starttime ) -as [ string ]) -split ' \. ' )[ 0 ] ReTweet this Tip!
1 2 Next >
Copyright 2012 All rights reserved.