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

Power Tips

Power Tips

Syndication

  • Checking Disk Partitions and Block Size

    WMI is a treasure chest full of information. This line will read local partitions along with their block sizes: Get-WmiObject -Class Win32_Diskpartition | Select-Object -Property __Server , Caption , BlockSize Use Get-WmiObject's parameter -ComputerName...
  • Converting Excel CSV to UTF8

    When you export Microsoft Excel spreadsheets to CSV files, Excel by default saves CSV files in ANSI encoding. That's bad because special characters will break once you import the data into PowerShell using Import-Csv. To make sure special characters...
  • Finding All PowerShell Profile Scripts

    Sometimes it can get confusing which startup scripts run when PowerShell starts. There can be plenty, and they may be different, depending on whether you use the PowerShell console, the ISE, or yet another host. Knowing about your profile scripts can...
  • Creating Objects with CSV

    There are many ways to create custom objects. Here's a creative solution that can be useful in many scenarios: create a text-based comma-separated list of values, and use ConvertFrom-Csv to produce objects: for ( $x = 0 ; $x -lt 20 ; $x ++ ) { ( ...
  • Finding Scripts by Keyword

    With an increasing number of PowerShell scripts on your hard drive, it can become hard to find the script you are looking for. Here's a helper function called Find-Script. Simply submit a keyword, and PowerShell will locate any script within your...
  • Setting Monitor Brightness

    If your display driver supports WMI, then you can change the display brightness using PowerShell - event on remote machines! Here's the function: function Set-MonitorBrightness { param ( [ Parameter ( Mandatory = $true )] [ Int ][ ValidateRange (...
  • Check Monitor Brightness

    If you want to check your current display brightness (preferably on notebooks, of course), here's a quick function: function Get-MonitorBrightness { param ( $ComputerName , $Credential ) Get-WmiObject -Namespace root / WMI -Class WmiMonitorBrightness...
  • Creating Symbolic Links

    Symbolic links work very similar to "regular" link files (*.lnk): they can point to virtually any file or folder and even UNC paths. Unlike lnk-files, to create symbolic links you need full Administrator privileges, and users cannot access the...
  • Testing Administrator Privileges

    To test whether a script is run by an Administrator with full privileges (UAC elevated), here is an unusual approach that illustrates the enormous flexibility in PowerShell: function Test-Admin { [ bool ](( whoami /groups ) -match "S-1-16-12288"...
  • Creating Hard Links

    Hard links are file "phantoms" in the NTFS file system. They make one file visible in multiple file system locations (within one volume). So the file occupies space only where it originally was stored but is also available elsewhere. This can...
  • Showing Hidden Files in File Explorer

    PowerShell can easily read and write to the Registry, the central store for Windows settings. Here's a function that can turn the display of hidden files in File Explorer on and off. The clever part is not necessarily writing new values to the Registry...
  • Verbose Output for PowerShell Functions

    To add on-demand verbose output to your PowerShell functions, make sure your functions support the common parameters by adding the CmdletBinding attribute. This is the basic template: function test { [ CmdletBinding ()] param () } Next, add Write-Verbose...
  • Copying Results to Clipboard

    To easily copy cmdlet results to other applications, simply pipe them to clip.exe. Next, paste the results into whatever application you want: Get-Service | clip ReTweet this Tip!
  • Turn Out-GridView into Selection Dialog

    Finally, in PowerShell 3.0, Out-GridView can turn into a versatile selection dialog - just add the new parameter -PassThru and watch: $Title = ' Select one or more files to open ' Get-ChildItem -Path $env:windir -Filter * . log | Out-GridView...
  • Three Most Useful ISE Tricks

    If you use PowerShell 3.0 and the ISE editor, then here are the three most useful tricks you should know: 1. Press CTRL+J to open a list of predefined code snippets for loops, conditions, functions, and workflows. This will get you started in no time...
« First ... < Previous 26 27 28 29 30 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.