PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Forum experts available to answer your PowerShell questions

Power Tips

Power Tips

Syndication

  • Finding Process Owners and Sessions

    Get-Process returns a lot of information about running tasks but it does not return the process owners or the session a process is logged on to. There are built-in console tools like tasklist that do provide this information. By asking these tools to...
  • Easier Parameter Attributes in PowerShell v3

    In PowerShell v2, to declare a function parameter as mandatory, you would decorate the parameter like this: param ( [ Parameter ( Mandatory = $true )] $p ) in PowerShell v3 , those attributes default to $true , so you get away with : param ( [ Parameter...
  • Exploring Group Membership

    To find out the groups your account belongs to, there is a command line tool called whoami . This tool supports options to output the information as comma-separated values. PowerShell can pick up CSV data and convert it to real objects. So with one simple...
  • Installing PowerShell v3 Help

    PowerShell v3 comes without help files. To get help, you need to download the help files first. In an elevated PowerShell console, use this command: PS > Update-Help -Force Currently, help is available only on English systems. To use English help on...
  • Controlling PSComputerName in Remoting Data with PowerShell

    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...
  • Listing Windows Updates with PowerShell

    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 =...
  • Determine Functions Pipeline Position with PowerShell

    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...
  • Displaying Balloon Tips with PowerShell

    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...
  • Extracting Icons with PowerShell

    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...
  • Saving History to Script with PowerShell

    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...
  • Forwarding Selected Parameters with PowerShell

    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...
  • Clean Your Temp Folder with PowerShell

    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 ) ...
  • Filtering Files or Folders with PowerShell

    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 ...
  • Office365 Cmdlets with PowerShell

    Office365 comes with a complete set of PowerShell cmdlets. To review the cmdlets and what you can do with them, visit this URL: http://onlinehelp.microsoft.com/en-us/office365-enterprises/hh125002.aspx ReTweet this Tip!
  • Use Select-String with Context in PowerShell

    Select-String can find lines with a specific keyword. It can also include context-relevant lines before and after that line. This will filter the result from ipconfig to focus on your network adapter parameters only: ipconfig | Select-String LAN -context...
« First ... < Previous 26 27 28 29 30 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.