Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus


13 Free SQL Tools from Idera


Free Ebook: Mastering Powershell

Archives

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
  • Test-Driving Scripts without Aliases

    All PowerShell versions Aliases can be cool in interactive PowerShell but should not be used in scripts. In scripts, use the underlying commands (so use “Get-ChildItem” instead of “dir” or “ls”). To test drive a script...
  • Creating Colorful HTML Reports

    All PowerShell versions To turn results into colorful custom HTML reports, simply define three script blocks: one that writes the start of the HTML document, one that writes the end, and one that is processed for each object you want to list in the report...
  • Creating New Shares

    All PowerShell versions WMI can easily create new shares. Here is sample code that will create a local share: $ShareName = ' NewShare ' $Path = ' c:\123 ' If ( ! ( Get-WmiObject -Class Win32_Share -Filter "name='$ShareName'"...
  • Useful Path Manipulation Shortcuts

    All PowerShell Versions Here are a bunch of useful (and simple to use) system functions for dealing with file paths: [ System.IO.Path ] :: GetFileNameWithoutExtension ( ' file.ps1 ' ) [ System.IO.Path ] :: GetExtension ( ' file.ps1 ' ...
  • Getting Active Directory Account Information

    In a previous script you have discovered how easy it is to find Active Directory accounts with just some simple PowerShell code. The result is a search result object, not the actual account object. To get more detailed information about an account, use...
  • Searching in Different Domains

    When you use the ADSISearcher type accelerator to find Active Directory accounts, it defaults to the current domain you are logged on to. If you need to find an account in a different domain, make sure you define the search root accordingly. This example...
  • Obfuscating Credentials

    How can you securely embed confidential passwords in a PowerShell script? You can't. But you can make it harder for people to discover the secret. Here is a code generator script that is designed to run inside the PowerShell ISE editor: # ask for...
  • 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...
  • 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...
  • Speaking English and German (and Spanish, and you name it)

    Windows 8 is the first operating system that comes with fully localized text-to-speech engines. So you can now have PowerShell speak (and curse) in your mother tongue. At the same time, there is always an English engine, so your computer is now bilingual...
  • Use Open File Dialog

    All PowerShell versions To add some sophistication to your script, here is a simple function that opens the OpenFile dialog and lets the user pick a file. function Show-OpenFileDialog { param ( $Title = ' Pick a File ' , $Filter = ' All|*...
  • Finding Process Owner

    PowerShell Version 3 or better Get-Process gets you a list of all running processes, but it will not reveal the process owner. To find the process owner, you would need to ask the WMI service, for example. To make this easier, here is a little helper...
  • Who Is Listening? (Part 1)

    The good oldfashioned netstat.exe can tell you the ports that applications listen on. The result is plain-text, though. PowerShell can use regular expressions though to split the text into CSV data, and ConvertFrom-Csv can then turn the text into real...
  • Invoke-Expression is Evil

    It can't be reiterated too often: try and avoid the use of Invoke-Expression (Alias: iex). This cmdlet executes whatever it receives and is prone to SQL-injection like attacks. Take a look at this strange one-liner, and run it in a PowerShell console...
  • Do Not Mix Different Objects!

    If you do output completely different objects, you may lose information. Take a look at this example: #requires -Version 2 $hash = @ { Name = ' PowerShell Conference EU ' Date = ' April 20, 2016 ' City = ' Hannover ' URL = '...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.