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
  • Case-Sensitive Hash Tables

    PowerShell hash tables are, by default, not case sensitive: PS > $hash = @ {} PS > $hash . Key = 1 PS > $hash . keY = 2 PS > $hash . KEY 2 If you need case-sensitive keys, you can create the hash table this way: PS > $hash = New-Object...
  • Creating Byte Arrays

    You can try this to create a new empty byte array with 100 bytes: $byte = New-Object Byte [] 100 Try this if you need to create a byte array with a default value other than 0: $byte = [ Byte []] ( , 0xFF * 100 ) ReTweet this Tip!
  • Quickly Changing File Extensions

    If you want to quickly exchange a file extension to create a "bak" backup version or generate a new file name for output, you should use the ChangeExtension() method: $oldpath = ' c:\test\datei.csv ' $newpath = [ System.IO.Path ] ::...
  • Grouping Files Based On Size

    In a previous tip, we showed you how to group using your own criteria. Group-Object can also auto-create hash tables so that you can easily create groups of objects of a kind. Here is an example: $criteria = { if ( $_ . Length -lt 1 KB ) { ' tiny...
  • Grouping Using Custom Criteria

    Try using Group-Object to group objects by any property: PS > Get-Process | Group-Object -property Company You can also submit a script block and calculate the grouping criteria yourself. The next example shows you how to group by file size into three...
  • Parsing Text-Based Log Files - Faster!

    In a previous tip, we showed you how to parse text-based log files using the PowerShell pipeline. However, the pipeline has considerable overhead. Without the pipeline approach, you can get the same results about 10-times faster: foreach ( $line in (...
  • Parsing Text-Based Log Files

    Extracting useful information from huge text-based log files isn’t necessarily a difficult task. Check out this line: PS > Get-Content $env:windir\windowsupdate.log -Encoding UTF8 | Where-Object { $_ -like ' *successfully installed* '...
  • Finding IP Addresses

    Sometimes, classic tools like ipconfig.exe can yield useful information that you'd like to integrate with PowerShell. Here is sample code that illustrates how to grab all IPv4 addresses from ipconfig output: PS > ipconfig | Where-Object { $_ -like...
  • Calculate Total Folder Size

    Here is a useful function that you can use to calculate the total size of a folder: function Get - FolderSize ( $path ) { Get-ChildItem $path -Recurse -ea 0 -Force | Measure-Object -Property Length -Sum | Select-Object -ExpandProperty Sum } For example...
  • 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...
  • 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...
  • 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...
  • 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...
  • 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 ' ,...
  • 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...
« First ... < Previous 59 60 61 62 63 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.