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
  • 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.-]...
  • Find multiple matches

    When you want to find matches based on regular expressions, PowerShell will only support the -match operator which finds the first match. There does not seem to be a -matches operator that returns all matches. You can use Select-Object like so to find...
  • 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...
  • 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!
  • 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...
  • Find system restore points

    Windows Update and Software installations will frequently create system restore points. Run this to get a list of such events: Get-EventLog -LogName application -InstanceId 8194 | ForEach-Object { $i = 1 | Select-Object Event , Application; ` $i . Event...
  • Secret history shortcut

    PowerShell will keep a history of the commands you entered and then you can list the history with Get-History, configuring the maximum length of that history with $MaxHistoryCount. This will tell PowerShell to keep the last 1,000 command lines in your...
  • Error handling for native commands

    When you need to handle errors created by native commands, you can use a wrapper function like Call. It will automatically discover when a native command writes to the error stream and return a warning: function Call { $command = $Args -join " "...
  • Calculate time zones

    If you need to find out the time in another time zone, you can convert your local time to Universal Time and then add the number of offset hours to the time zone you want to display: (( get-date ) . toUniversalTime ()) . AddHours ( 8 ) ReTweet this Tip...
  • 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...
  • Creating IP segment lists

    If you need a list of consecutive IP addresses, you can check out this function. You can see that it takes a start and an end address and then returns all IP addresses in between: function New-IPSegment ( $start , $end ) { $ip1 = ([ System.Net.IPAddress...
  • Getting significant bytes

    If you need to split a decimal into bytes, you can use a function called ConvertTo-HighLow, which uses a clever combination of type casts to get you the high and low bytes: function ConvertTo-HighLow { param ( $number ) $result = [ System.Version ][ String...
  • 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...
  • 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...
  • 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...
« First ... < Previous 59 60 61 62 63 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.