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
  • Find Local Groups

    On Windows 7, net.exe can list all local groups. To use this information with PowerShell, try this simple wrapper: function Get-LocalGroup { net localgroup | Where-Object { $_ . StartsWIth ( ' * ' ) } | ForEach-Object { $_ . SubString ( 1 ) }...
    Filed under:
  • Find Local Users

    On Windows 7, the easiest way to find local user accounts is to use net.exe. Here is a simple PowerShell wrapper called Get-LocalUser: function Get-LocalUser { $users = net user $users [ 4 .. ( $users . count - 3 )] -split ' \s+ ' | Where-Object...
    Filed under:
  • Escape Regular Expressions

    PowerShell supports regular expressions in a lot of areas which is why the following code fails: ' c:\test\subfolder\file' -split '\ ' Split expects a regular expression and fails when you use special characters like "\". To...
  • Monitor Open Files

    In a previous tip we introduced the command openfiles which lists and disconnects files that were opened remotely on your machine. Openfiles can also track open files on your local machine. You pay for it with a lower overall system performance because...
    Filed under:
  • Finding Open Files

    If you'd like to see which files are opened by network users on your machine, there is an internal command for it. All you need are local admin privileges, so you may want to launch PowerShell with full privileges first. And then, enter this: PS >...
    Filed under:
  • Removing File Extensions (Safe)

    In a previous tip we showed that Trim() is an unsafe way for removing file extensions. A safe way uses .NET methods: [ system.io.path ] :: GetFileNameWithoutExtension ( ' c:\test\report.txt ' ) Report ReTweet this Tip!
  • Removing File Extensions (Unsafe)

    Some users use Trim() to remove file extensions like this: ' c:\test\file.txt'.Trim('.txt ' ) c:\test\file This seems to work great, but in reality, Trim() removes all the characters you submitted from the beginning and end of the text...
  • Finding Useful WMI Classes

    To find the most useful WMI classes you can use Get-WmiObject, and let PowerShell provide you with a hand-picked list: Select-XML $env:windir\System32\WindowsPowerShell\v1.0\types.ps1xml -Xpath / Types / Type / Name | ForEach-Object { $_ . Node . innerXML...
  • Finding Type Definitions

    PowerShell enhances many .NET types and adds additional information. These changes are defined in xml files. To list all .NET types that get enhanced by default, use this: Select-XML $env:windir\System32\WindowsPowerShell\v1.0\types.ps1xml -Xpath / Types...
  • 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:
« First ... < Previous 57 58 59 60 61 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.