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
  • Analyze Cmdlet Results

    There are two great ways to analyze the results a cmdlet returns: you can send the results to Get-Member to get a formal analysis, telling you the properties, methods and data types, and you can send them to Select-Object to view the actual property content...
  • Listing Process Owners

    In a previous tip, you learned that there is a hidden host process named wsmprovhost.exe whenever someone else visits your computer using PowerShell remoting. Provided you have local admin rights, this piece of code creates a new function called Get-PSRemotingVisitor...
  • 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...
« First ... < Previous 59 60 61 62 63 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.