July 2011 - Power Tips

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 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:
  • 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:
  • Getting Network Adapter Settings

    To view the configuration details of a network adapter, you can specify the network adapter connection ID as it appears in your control panel. By linking the WMI result to the corresponding Win32_NetworkAdapterConfiguration class, you get to the actual...
  • 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:
  • 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:
  • 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...
  • 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...
  • 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...
  • Combining Network Adapter Information

    In a previous tip you learned that WMI network adapter information is separated into two classes. Win32_NetworkAdapter represents the hardware, and Win32_NetworkAdapterConfiguration contains the configuration details. To mix information from both classes...
  • 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!
  • 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...
  • Find Local Group Members

    If you'd like to list all members of local groups, encapsulate net.exe and make it a PowerShell function: function Get - LocalGroupMember { param ( [ Parameter ( Mandatory = $true )] $name ) try { $ErrorActionPreference = ' Stop ' $users ...
    Filed under: ,
  • 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...
  • Shortcut to Network Cards

    To quickly access the settings for your network cards, use this line from within PowerShell: explorer.exe ' ::{7007ACC7-3202-11D1-AAD2-00805FC1270E} ' You can also create a new link on your desktop and use this shortcut as target path. ReTweet...
  • 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:
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.