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

Power Tips

Power Tips

Syndication

  • Pinging Computers

    There are multiple ways how you can ping computers. Here is a simple approach that uses the traditional ping.exe but can be easily integrated into your scripts: function Test-Ping { param ([ Parameter ( ValueFromPipeline = $true )] $Name ) process { ...
  • Playing a Sound on Error

    To catch a user’s attention, your script can easily play WAV sound files. Here is a simple function: function Play-Alarm { $path = " $PSScriptRoot\Alarm06.wav " $playerStart = New-Object Media.SoundPlayer $path $playerStart . Load () ...
  • Getting DNS IP Address from Host Name

    There is a tiny .NET function called GetHostByName() that is vastly useful. It will look up a host name and return its current IP address: [ System.Net.DNS ] :: GetHostByName ( ' someName ' ) With just a simple PowerShell wrapper, this is turned...
  • Reading and Writing NTFS Streams

    When a file is stored on a drive with NTFS file system, you can attach data streams to it to store hidden information. Here is a sample that hides PowerShell code in an NTFS stream of a script. When you run this code, it creates a new PowerShell script...
  • Create New Local Admin Account on the Fly

    Ever needed a new local administrator account for testing purposes? Provided you are already Administrator, and you opened a PowerShell with full Administrator privileges, adding such a user is a matter of just a couple of lines of code: $user = '...
  • Launching Any Excel Version

    Microsoft Excel is an example of a program that is not easy to launch directly: the path to Excel may be different, depending on Office version and platform (32-bit or 64-bit). PowerShell has a very clever cmdlet to run programs: Get-Process. Traditionally...
  • Unblocking Download Files

    Any file you download from the Internet or receive via email get marked by Windows as potentially unsafe. If the file contains executables or binaries, they will not run until you unblock the file. PowerShell 3.0 and better can identify files with a "download...
  • Eliminating Empty Results

    To exclude results that have empty properties, you can easily use Where-Object. For example, when you run Get-Hotfix, and you only want to see hotfixes that have a date for InstalledOn, here is the solution: Likewise, to get only network adapters from...
  • Hidden Array Extensions in PowerShell 4.0

    PowerShell 4.0 (final version as found in Windows 8.1) has Foreach and Where built directly into arrays. This is a geek stuff, so there is no apparent advantage to it over using the traditional pipeline (except maybe for speed). This line will get only...
  • Opening Files in ISE Editor

    If you'd like to open a script in the ISE editor, one quick way is using the command "ise". For example, to open your profile script (the one that starts automatically with each ISE launch), try this: You can now easily add or remove commands...
  • Block Comment in PowerShell ISE

    Beginning in PowerShell 3.0, when you press and hold ALT and then select something, you get a block selection. If you make this selection as narrow as possible (you will only see a tiny blue line), you can now easily add or remove characters to the selection...
  • Finding Logged-On User on Remote Machine

    In a previous tip we used quser.exe to find the currently logged-on user on the local machine. Here is now a function that also allows us to find the currently logged-on user on a remote machine. As an extra benefit, the returned information is appended...
  • Finding Logged-On User

    There is a helpful console application called quser.exe which will tell you who is logged on to a machine. The executable returns plain text, but with the help of a little regular expression, this text can be converted to CSV and then imported into PowerShell...
  • Finding Logon Failures

    Whenever someone logs on with invalid credentials, there will be a log entry in the security log. Here is a function that can read these events from the security log (Admin privileges needed). It will then list all the invalid logons found in the log...
  • Change Desktop Wallpaper

    To change the current desktop wallpaper and make this change effective immediately, PowerShell can tap into the Windows API calls. Here is a function that changes the wallpaper immediately: function Set-Wallpaper { param ( [ Parameter ( Mandatory = $true...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.