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
  • 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...
  • Finding Parameter Aliases

    Sometimes, cmdlet parameters have additional alias names, but these names aren't well documented. Here is a script that will list all parameter alias names for all cmdlets: $common = "Verbose,Debug,ErrorAction,WarningAction,ErrorVariable,WarningVariable...
  • Playing Sound in PowerShell

    If you would like to catch a user’s attention, you can make PowerShell beep like this: [ System.Console ]:: Beep () [ System.Console ]:: Beep (1000,300) A nicer sound can be played this way: [ system.media.systemsounds ]:: Beep.play () [ system...
  • Identifying Computer Hardware

    If you must identify computer hardware, you could do so on the hard drive serial number: Get-WmiObject -Class Win32_DiskDrive | Select-Object -ExpandProperty SerialNumber Unless the hard drive is exchanged, this number provides a unique identifier. ReTweet...
  • Formatting a Drive

    In Windows Vista and higher, there is a new WMI class called Win32_Volume that you can use to format drives. However, you should be careful when formatting data on a drive. The following line will format drive D:\ using NTFS file system, provided you...
  • Sending Mails With Outlook

    You can use PowerShell to automatically prepare your e-mails and send them via Outlook. The code requires that you first launch Outlook as an application. It will not work when Outlook has not yet been started. Start-Process Outlook $o = New-Object -com...
  • Setting Mouse Position

    PowerShell can place the mouse cursor anywhere on your screen. Here's the code: [ system.Reflection.Assembly ]:: LoadWithPartialName ( "Microsoft.Forms" ) | Out-Null [ System.Windows.Forms.Cursor ]:: Position = New-Object System.Drawing...
  • Comparing Services

    Compare-Object can help when troubleshooting computers. For example, you should try this to compare the service status on two machines and find out where services are configured differently: $machine1 = Get-Service -ComputerName server1-or -IP1 $machine2...
  • Checking Whether User or Group Exists

    To find out whether a given local or domain user/group exists, you can simply use the static method Exists(): [ ADSI ]:: Exists ( 'WinNT://./Tobias1' ) This will check whether there is a local account named "Tobias1." To check domain...
« First ... < Previous 72 73 74 75 76 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.