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

Power Tips

Power Tips

Syndication

  • 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...
  • 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...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.