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
  • Be Aware of Side Effects

    There are plenty of low level system functions that PowerShell can use. This one, for example, creates a temporary file name: [ System.IO.Path ] :: GetTempFileName () However, it does not only do that. It also actually creates the file. So if you use...
  • Bulk File Renaming

    Let's assume you have a bunch of scripts (or pictures or log files or whatever) in a folder, and you'd like to rename all files. The new file name should, for example, have a prefix, then an incrementing number. Here's how you could do that...
  • Getting DateTaken Info from Pictures

    If you'd like to reorganize your picture archive, then here is a piece of code that reads the "DateTaken" information from picture files. The example uses a system function to find out the MyPictures path, then recursively searches for all...
  • Reading Installed Software Remotely

    Most software registers itself in the Registry. Here is a piece of code that reads all installed software from the 32-bit and 64-bit hive and works locally and remotely as well. It can serve as a good example on how to remotely read Registry keys, too...
  • gpupdate on Remote Machines

    To run gpupdate.exe remotely, you could use a script like this: function Start-GPUpdate { param ( [ String []] $ComputerName ) $code = { $rv = 1 | Select-Object -Property ComputerName , ExitCode $null = gpupdate.exe /force $rv . Exitcode = $LASTEXITCODE...
  • Getting Database Connection String

    Have you ever been puzzled just what the connection string would look like for a given database? When you create a new data source in Control Panel, a wizard guides you through the creation process. Here is a way to utilize this wizard and get back the...
  • Use Splatting to Encapsulate WMI Calls

    Splatting is a great way of forwarding parameters to another cmdlet. Here is an example that can be used to encapsulate WMI calls and make them available under different names: function Get-BIOSInfo { param ( $ComputerName , $Credential , $SomethingElse...
  • Submitting Parameters through Splatting

    Splatting was introduced in PowerShell 3.0, but many users still never heard of this. It is a technique to programmatically submit parameters to a cmdlet. Have a look: $infos = @ {} $infos . Path = ' c:\Windows ' $infos . Recurse = $true $infos...
  • Getting Group Membership - Fast

    If you need to find out the Active Directory groups your user account is in, typically you would query the Active Directory, and you would have to find the nested group memberships as well. Here is a technique that gets you your own group memberships...
  • 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...
< Previous 1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.