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
  • Working with Path Names

    The .NET System.IO.Path class has a number of very useful static methods that you can use to extract file extensions. Here is how you can get a list of available methods: [ System.IO.Path ] | Get-Member -Static And here is an example on how to use one...
  • Finding A Users Desktop Folder

    The .NET Environment class can provide the paths to common folders like a user desktop: Environment]:: GetFolderPath ( "Desktop" ) Use this line to get a list of allowed folder names: [ Enum ]:: GetNames ([ System.Environment + SpecialFolder...
  • Writing Your Own Event Log Entries

    If you have registered a new event log source, such as "PowerShellScripts" as described in the previous tip, you can now write your own Events: Write-EventLog -LogName Application -Source PowerShellScripts -EntryType Warning -EventId 12345 ...
  • Adding New Event Log Sources

    Every event log maintains a list of registered sources. You need a source name if you want to write your own event log entries. Make sure you have administrator privileges to add a new source called "PowerShellScripts" to your application log...
  • Lowering Process Priority

    Sometimes, you may want to lower process priority for some processes. That's a PowerShell one liner. Note that the next line lowers priority for all Notepad processes to "below normal:" Get-Process notepad | ForEach-Object { $_ . PriorityClass...
  • Getting Help on WMI Methods

    Have you ever wanted to get a list of all WMI methods present inside a specific WMI class – plus a meaningful description and a list of all the supported return values? Here is how: $class = [ wmiclass ] "Win32_NetworkAdapterConfiguration"...
  • Renewing all DHCP Leases

    Some WMI classes contain static methods. Static methods do not require an instance. ([ wmiclass ] "Win32_NetworkAdapterConfiguration" ). RenewDHCPLeaseAll (). ReturnValue ReTweet this Tip!
  • Calling ChkDsk via WMI

    Some WMI classes contain methods that you can call to invoke some action. For example, the next line initiates a disk check on drive D: ([ wmi ] "Win32_LogicalDisk='D:'" ). Chkdsk ( $true , $false , $false , $false , $false , $true ...
  • Getting Help for WMI Classes

    In a previous tip, you discovered how to search for WMI classes like Win32_VideoController. Now, what exactly is the purpose of this class? You can retrieve Help information for any WMI class with the next lines of code,: $class = [ wmiclass ] 'Win32_VideoController'...
  • Finding Interesting WMI Classes

    WMI is a huge repository. If you want to get to useful information, you will need to specify the name of a valid WMI class. Fortunately, it is easy to search for interesting classes. You can simply use Get-WmiObjectand the -list parameter in conjunction...
  • Rename Drive Label

    WMI can also read any drive label (the name that appears next to a drive inside Explorer), and you can change the drive label, too—provided you have administrator privileges. This code renames drive c:\ to "My Harddrive": $drive = [ wmi...
  • Remove Empty Entries

    One little known fact is that Where-Object is a cool and simple way of removing empty objects. Let's say you want to list all network adapters that have an IP address. You can simply add Where-Object and specify the object property that needs to have...
  • Finding Your Current Domain

    Try this quick and simple way to find out the domain name that you are currently connected: [ ADSI ] "" The domain name is returned if you are currently connected to a domain. Otherwise, you will receive an exception. You can also return arbitrary...
  • Retrieving Clear Text Password

    Get-Credential is a great way of prompting for credentials, but the Password you enter into the dialog will be encrypted. Sometimes, you may need a clear text password. Here is one way to restore the clear text password entered into the dialog: $cred...
  • Use PowerShell Cmdlets!

    Whenever possible, try to avoid raw .NET access if you would like to create more readable code. For example, the following line returns the current date: [ System.DateTime ]:: Now Here is a much better approach: simply use Get-Date: Get-Date Remember...
« First ... < Previous 72 73 74 75 76 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.