January 2011 - 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
  • Accessing Web Services

    Did you know PowerShell can access public and private Web services? The piece of code below will connect to a global weather service providing airport weather reports from around the globe: $a = New-WebServiceProxy 'http://www.webservicex.net/globalweather...
  • Create HTML report in style

    Also, here is a template that shows you how to change to a nicer font if you want to export PowerShell results as HTML report.. It will generate a process list and display it in a simple window: $head = @ ' <style> body { font-family:Consolas...
  • Launching Scripts Externally

    For example, you should use this line if you want to launch a *.ps1 PowerShell script externally from outside PowerShell via desktop shortcut or from inside a batch file: powershell.exe -nologo -executionpolicy bypass -noprofile -file "C:\myscript...
  • Get All Logged On Users

    In a previous tip, you learned how to determine who the user is logged onto the physical machine. However, this will not discover logged-on terminal service users or users inside virtual machines. You must use the code below to find those: $computername...
  • Comparing Hotfixes

    If you want to check hotfixes, you should compare installed hotfixes on a master image with some other machine. Go ahead and use Compare-Object and this approach: $machine1 = Get-HotFix -ComputerName server-master $machine2 = Get-HotFix -ComputerName...
  • Backing Up Event Log Files

    WMI provides a method to backup event log files as *.evt/*.evtx files. The code below creates backups of all available event logs: Get-WmiObject Win32_NTEventLogFile | ForEach-Object { $filename = "$home\" + $_ . LogfileName + '.evtx'...
  • Opening Excel Reports in a New Window

    When opening CSV files with Excel from PowerShell, you may receive exceptions if the particular file was opened by Excel already: Invoke-Item c:\files\ report.csv You can work around this by telling Excel to open a new window for the CSV file. Here is...
  • Loading .EVT/.EVTX Event Log Files

    If customers send in dumped event log files, there is an easy way to open them in PowerShell and analyze content: Get-WinEvent! The -Path parameter will allow you to read in those binary dumps and display the content as an object. You should use this...
  • Checking Loaded Formats

    PowerShell Snapins and Modules can add format files that describe how Powershell should auto-format object types. Use this line to check which format files have been loaded: $host . Runspace.RunspaceConfiguration.Formats | Select-Object -ExpandProperty...
  • Checking Loaded Assemblies

    Use this line to check which .NET assemblies are currently loaded into PowerShell: $host . Runspace.RunspaceConfiguration.Assemblies ReTweet this Tip!
  • Checking -STA Mode

    PowerShell needs to run in STA mode to display Windows Presentation Foundation (WPF) windows. ISE runs in STA mode by default whereas the console will need to be launched explicitly with the -STA switch. To check whether STA mode is currently enabled...
  • Filtering Multiple File Types

    If you want to filter files based on multiple extensions, you should use this filter: filter Where-Extension { param ( [ String []] $extension = ( '.bmp' , '.jpg' , '.wmv' ) ) $_ | Where-Object { $extension -contains $_ . Extension...
  • Cleaning Transcript

    When you run Start-Transcript, PowerShell will document all console input and output in a file. To remove all output and create a file with your PowerShell commands only, you should use this piece of code: $path = "$home\Documents\allcommands.txt"...
  • Automated Authentication

    You will not want a credential dialog to pop up if you need to run scripts unattended that need to authenticate using credentials. Here is an example of how to hard-code credentials into your scripts. The example launches a process automatically as a...
  • Get Logged On User

    You can use this code to find out which user is locally logged on a machine: $computername = 'SomeMachine-or-IP' Get-WmiObject Win32_ComputerSystem -ComputerName $computername | Select-Object -ExpandProperty UserName Note that this will always...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.