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
  • Use Out-Host instead of More

    PowerShell Console Note that any of this will only work in a “real” console. It will not work in the PowerShell ISE. To output data page by page, in the PowerShell console many users pipe the result to more.com, like in the old days: PS>...
  • Invoke-Expression is Evil

    All PowerShell versions Try and avoid Invoke-Expression in your scripts. This cmdlet takes a string and executes it as if it was a command. In most scenarios, it is not needed, but introduces many risks. Here is a--somewhat constructed--show case: function...
  • Display Command History in PowerShell Console

    All PowerShell Versions In the PowerShell console (not the PowerShell ISE), you can open a list with the last commands you entered, simply by pressing F7. There will be no list if you did not execute any command yet, obviously. ALT+F7 will clear the command...
  • Importing and Installing Certificate

    All PowerShell versions To programmatically load a certificate from a file and install it in a specific location inside the certificate store, have a look at this script: $pfxpath = ' C:\temp\test.pfx ' $password = ' test ' [ System.Security...
  • Using Notepad to Print Things

    All PowerShell versions To print a text-based file with the Notepad, try using this line (replace the path to the text file with some path that is meaningful to you, or else you will print a rather long system log file): Start-Process -FilePath notepad...
  • 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'"...
  • Changing PowerShell Priority

    All PowerShell versions Maybe you’d like a PowerShell script to work in the background, for example copy some files, but you do not want the script to block your CPU or interfere with other tasks. One way to slow down PowerShell scripts is to assign...
  • Reading In PFX-Certificate

    All PowerShell versions When you use Get-PfxCertificate, you can read in PFX certificate files and use the certificate to sign scripts. However, the cmdlet will always interactively ask for the certificate password. Here is some logic that enables you...
  • Accessing SQLServer Database

    All Versions, SQL Server You are running an SQL Server? Then here is a PowerShell script template you could use to run an SQL query and retrieve the data. Simply make sure you fill in the correct user details, server address, and SQL statement: $Database...
  • 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...
  • Turning Off “FullLanguage” Mode

    All PowerShell versions PowerShell can be restricted in many ways. One is to set the language mode from “FullLanguage” to “RestrictedLanguage”. It is a way of no return, at least unless you close and re-open PowerShell: $host ...
  • Controlling Execution of Executables

    All PowerShell versions PowerShell treats executables (files with extension EXE) like any other command. You can, however, make sure that PowerShell will not execute any or execute only a list of approved applications. The default setting allows any EXE...
  • Faking Object Type

    PowerShell 3 and later The internal PowerShell ETS is responsible for converting objects to text. To do this, it looks for a property called “PSTypeName”. You can add this property to your own objects to mimic another object type and make...
  • Creating New Objects

    PowerShell 3 and later Here is a simple, yet effective, way of creating new custom objects: $object = [ PSCustomObject ] @ { Name = ' Weltner ' ID = 123 Active = $true } This will produce full-blown PowerShell objects with preset property values...
  • Using PowerShell Remoting without Domain

    PowerShell 3 and later By default, when you enable PowerShell remoting via Enable-PSRemoting, then only Kerberos authentication is enabled. This requires both computers to be in the same domain (or trusted domains), and it only works when you specify...
< Previous 1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.