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

Power Tips

Power Tips

Syndication

  • Setting Registry Permissions

    Setting permissions for Registry keys isn't trivial. With a little trick, though, it is no big deal anymore. First, open REGEDIT and create a sample key. Next, right click the key and use the UI to set the permissions you want. Now, run this script...
  • Blocking Administrator Scripts

    If you know that your script requires Administrator privileges, then you should add this to the top of your script: #requires -runasadministrator This line makes sure the script will run only if the caller owns local Administrator privileges. The line...
  • Removing Selected NTFS Permissions

    Maybe you need to remove some permission settings from NTFS permissions. Let's assume you want to remove all permissions for a specific user because the user left the department. Note: Of course you can manage NTFS permissions per group, and setting...
  • PowerShell God Mode

    Before you can run a PowerShell script, the execution policy needs to allow this. Typically, you would use this line to enable script execution: However, if group policy has disabled script execution, then this line will not do you any good. In this case...
  • Checking Windows Updates

    To check all installed updates on a Windows box, there is a COM library you can use. Unfortunately, this library isn't very intuitive to use, nor does it work remotely. So here is a PowerShell function called Get-WindowsUpdate. It gets the locally...
  • Getting Free Cheat Sheets

    There are two great sources for PowerShell cheat sheets. One is the set of cheat sheets created by powershellmagazine.com which was just updated to cover PowerShell 4.0 and now also includes a sheet for Desired State Configuration (DSC). You can download...
  • Start to Look at DSC

    Desired State Configuration (DSC) is a new feature in PowerShell 4.0. With DSC, you can write simple configuration scripts and apply them to the local or a remote machine. Here is a sample script to get you started: Configuration MyConfig { # Parameters...
  • Compiling Binary Cmdlets

    PowerShell functions can mimick all the features found in a true binary cmdlet--but PowerShell functions are plain PowerShell code, so anyone can view it. If you are a developer and interested in creating binary cmdlets, here is a quick starter. It illustrates...
  • Adding and Resetting NTFS Permissions

    Whether you want to add a new NTFS access rule to a file or turn off inheritance and add new rules, here is a sample script that illustrates the trick and can serve you as a template. The script creates a test file, then defines a new access rule for...
  • Converting Text Arrays to String

    Occasionally, text from a text file needs to be read and processed by other commands. Typically, you would use Get-Content to read the text file content, then pass the result on to other commands. This may fail, though. And here is the caveat: Always...
  • ISE Bug Locks Debugger

    There is an obscure bug in the PowerShell ISE that may dead-lock the debugger. It affects PowerShell version 3.0 and 4.0. Here is a test script: $test = @" Some lines of text "@ $test Save this code as a script in your ISE editor, then set a...
  • Bulk Renaming Object Properties

    Occasionally, it may become necessary to bulk rename object properties to create better reports. For example, if you retrieve process objects, you may need to create a report with column headers that are different from the original object properties....
  • Fixing Display in Excel Reports

    When you send information to Microsoft Excel, it is converted to text using the built-in .NET ToString() method. This method typically does not convert well any arrays or non-primitive data types. Here is an example illustrating the problem. It creates...
  • Creating Excel Reports

    PowerShell objects can easily be opened in Microsoft Excel. Simply export the objects to CSV, then open the CSV file with the associated program (which should be Excel if it is installed). This creates a report of running processes and opens in Excel...
  • PowerShell does not support JSON Data Types

    By default, any object created from JSON uses String as a data type: $json = @" { "Name": "Weltner", "ID" : "123" } "@ $info = ConvertFrom-Json -InputObject $json $info . Name $info . ID JSON does support...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.