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
  • Detecting Remote Visitors

    Whenever someone connects to your computer using PowerShell remoting, there is a host process called wsmprovhost.exe. You can only see processes from other users if you have local admin privileges. If you do, this is how you detect remoting processes...
  • Echoing The Error Channel

    To control which output from a batch file is considered "a result" and which output should rather always be visible to the user, you can redirect information to StdErr when you want it to be excluded from the results. Take a look at this batch...
  • Make Sure Folder Exists

    To ensure that a given folder exists, you can stick to trial-and-error, and hide error messages: New-Item c:\somefolder\anotherfolder\yetanother -ItemType Directory -ea 0 | Out-Null This will create all missing folders and hide all error messages. If...
  • List NTFS Permissions

    To view NTFS permissions for folders or files, use Get-Acl. It won't show you the actual permissions at first, but you can make them visible like this: Get-Acl -Path $env:windir | Select-Object -ExpandProperty Access ReTweet this Tip!
    Filed under:
  • Duplicate Output

    Sometimes, you may want to store command results in a variable and at the same time, output it to the console. Once you assign results to a variable, however, the console will no longer show the results: PS > $result = Get-Process You should place...
  • Multiple Text Replace (Fast)

    In a previous tip, we showed you how to replace multiple different characters in a text using the Switch statement. While this works well, it is not very fast. The following approach is about 150-times faster: PS > $text = ' Österreich überholt...
    Filed under: ,
  • Speed Up Loops

    First, compare these two code samples: $array = 1 . .10000 Measure-Command { for ( $x = 0 ; $x -lt $array . Count ; $x ++ ) { $array [ $x ] } } Measure-Command { $length = $array . Count for ( $x = 0 ; $x -lt $length ; $x ++ ) { $array [ $x ] } } The...
    Filed under: ,
  • Set Clipboard

    If you are using Windows Vista or better, you can pipe text to clip.exe to copy it to your clipboard: Dir $env:windir | clip Here is another approach that you can use if your PowerShell host uses the STA mode: function Set-Clipboard { param ( $text )...
    Filed under: ,
  • Get-Clipboard

    If your PowerShell host uses the STA mode, you can easily read clipboard content like this: function Get-Clipboard { if ( $Host . Runspace . ApartmentState -eq ' STA ' ) { Add-Type -Assembly PresentationCore [ Windows.Clipboard ] :: GetText (...
    Filed under: ,
  • Test for STA mode

    By default, the PowerShell console does not use the STA mode whereas the ISE editor does. STA is needed to run Windows Presentation Foundation scripts and to use WPF-based dialog windows, such as Open. Here is how you can check to see whether your script...
  • Multiple Text Replace

    Imagine that you need to replace a number of different characters in a text. For example, you need to remove special characters or escape something. The switch statement can do that. You will just need to temporarily convert the text into a character...
  • Switch Accepts Arrays

    Did you know that the Switch statement can accept arrays? Use this sample to translate numbers into words: PS > switch ( 1 , 5 , 2 , 4 , 3 , 1 ) { 1 { ' one ' } 2 { ' two ' } 3 { ' three ' } 4 { ' four ' } 5 { '...
    Filed under:
  • Check For Numeric Characters

    Try this if you need to check a single character and find out whether or not it is numeric: PS > [ char ] :: IsNumber ( ' 1 ' ) True PS > [ char ] :: IsNumber ( ' A ' ) False The type Char has a bunch of other useful methods. Here...
  • Check Array Content With Wildcards

    You may know the -contains operator. Try using it to check whether an array contains a specific element: PS > $names = dir $env:windir | Select-Object -ExpandProperty Name PS > $names -contains ' explorer.exe ' True However, -contains does...
    Filed under:
  • Adding New PowerShell Drives

    You can add a bunch of interesting new drives to PowerShell with just a single line of code: [ System.Enum ] :: GetNames ([ System.Environment + SpecialFolder ]) | ForEach-Object { New-PSDrive -Name ( $_ ) -Root ([ System.Environment ] :: GetFolderPath...
« First ... < Previous 58 59 60 61 62 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.