May 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
  • Analyze automatic defragmentation

    Check out this line to visualize when your system defragmented your hard drives: get-eventlog -LogName Application -InstanceId 258 | ForEach-Object { $i = 1 | Select-Object Date , Type , Drive; ` $i . Date = $_ . TimeWritten ; $i . Type , ` $i . Drive...
  • Finding multiple RegEx matches

    In a previous tip, you learned that Select-Object can find multiple matches. Here is a function called matches. You can submit a regular expressions pattern and all text piped into matches will be matched: $pattern = ' \b[A-Z0-9._%+-]+@[A-Z0-9.-]...
  • Restart required

    Check out this line to determine when an installation required a system restart: Get-EventLog -InstanceId 1038 -LogName Application | ForEach-Object { $i = 1 | Select-Object Date , Product , Version , Company; ` $i . Date = $_ . TimeWritten ; $i . Product...
  • Find Dependent Services

    If you would like to check the implications of stopping a service, you should have a look at its dependent services: ( Get-Service spooler ) . DependentServices Or use Select-Object: get-service Spooler | Select-Object -expand DependentServices To stop...
  • RegEx Magic

    The [RegEx] type has a method called Replace(), which can be used to replace text by using regular expressions. This line would replace the last octet of an IP address with a new fixed value: PS > [ Regex ] :: Replace ( ' 192.168.1.200 ' ,...
  • Getting Full Admin Privileges

    You may sometimes get "Access Denied" exceptions, even though you have Admin privileges and used an elevated shell. For example, this can hit you when you are trying to enable security-relevant PowerShell settings, such as enabling PowerShell...
  • Copy Registry Hives

    You can use Copy-Item to quickly copy entire structures of registry keys and sub-keys in a matter of milliseconds. Take a look at this example – it creates a new registry key in HKCU and then copies a key with all of its values and sub-keys from...
  • Remove Keys From a Hash Table

    Once you create a hash table, it is easy for you to add new key-value pairs like this: PS > $myHash = @ {} PS > $myHash . Name = ' Tobias ' PS > $myHash . ID = 12 PS > $myHash . Location = ' Hannover ' PS > $myHash Name...
  • Use WMI to Create Hardware Inventory

    You can use Get-WMIObject to create a high-level hardware report. Instead of submitting a specific device class name, you should use a generic device class that applies to all hardware devices: PS > Get-WmiObject -Class CIM_LogicalDevice | Select-Object...
  • Windows license validation

    Search for the appropriate events in your event log to discover when Windows has validated your license: get-eventlog -LogName Application -InstanceId 1073745925 | Select-Object TimeWritten , Message ReTweet this Tip!
  • Translate EventID to InstanceID

    Sometimes, you may need to have the event ID for a system event, though what you really need is the instance ID. For example, Get-EventLog will only support instance IDs, but no event IDs. Here is a function that can translate event IDs into instance...
  • Running PowerShell on 64-bit systems

    On 64-bit systems, PowerShell will by default run in a 64-bit process. This can cause problems with snap-ins, some COM-objects (like ScriptControl) and database drivers that are designed to run in 32-bit processes. In this case, you can run them in the...
  • Making sure PowerShell scripts run in 32-bit

    If you are using code that can only run in a 32-bit environment (i.e. using old database drivers or COM objects), here is a solution that will re-launch the script in a 32-bit PowerShell when it is launched in a 64-bit environment: if ( $env:Processor_Architecture...
  • Test Internet connection

    Try this line if you would like to know whether a machine is currently connected to the Internet: [ Activator ] :: CreateInstance ([ Type ] :: GetTypeFromCLSID ([ Guid ] ' {DCB00C01-570F-4A9B-8D69-199FDBA5723B} ' )) . IsConnectedToInternet It...
  • Checking all event logs

    What if you would like to get a quick overview of all error events in any event log. Get-EventLog can only query one event log at a time. So, you can use -list to get the names of all event logs and then loop through them. The next line will get you the...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.