Tag Archives: MaxSamples

Import-Counter

NAME
    Import-Counter

SYNOPSIS
    Imports performance counter log files (.blg, .csv, .tsv) and creates the objects that represent each counter sample in the log.

SYNTAX
    Import-Counter [-Path] <string[]> [-Counter <string[]>] [-EndTime <DateTime>] [-MaxSamples <Int64>] [-StartTime <DateTime>] [<CommonParameters>]

    Import-Counter [-Path] <string[]> -ListSet <string[]> [<CommonParameters>]

    Import-Counter [-Path] <string[]> -Summary <switch> [<CommonParameters>]

DESCRIPTION
    The Import-Counter cmdlet imports performance counter data from performance counter log files and creates objects for each counter sample in the file. The PerformanceCounterSampleSet objects that it creates are identical to the objects that Get-Counter returns when it collects performance counter data.

    You can import data from comma-separated value (.csv), tab-separated value ( .tsv), and binary performance log (.blg) performance log files. If you are using .blg files, you can import multiple files (up to 32 different files) in each command. And, you can use the parameters of Import-Counter to filter the data that you import.

    Along with Get-Counter and Export-Counter, this feature lets you collect, export, import, combine, filter, manipulate, and re-export performance counter data within Windows PowerShell.

PARAMETERS
    -Counter <string[]>
        Imports data only for the specified performance counters. By default, Import-Counter imports all data from all counters in the input files. Enter one or more counter paths. Wildcards are permitted in the Instance part of the path.

        Each counter path has the following format. Notice that the ComputerName value is required in the path, even on the local computer.
             “\\<ComputerName>\<CounterSet>(<Instance>)\<CounterName>”

        For example:
                “\\Server01\Processor(2)\% User Time”
                “\Processor(*)\% Processor Time

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? true

    -EndTime <DateTime>
        Imports only counter data with a timestamp less than or equal to the specified date and time. Enter a DateTime object, such as one created by the Get-Date cmdlet. By default, Import-Counter imports all counter data in the files specified by the Path parameter.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -ListSet <string[]>
        Gets the performance counter sets that are represented in the exported files. Commands with this parameter do not import any data.

        Enter one or more counter set names. Wildcards are permitted. To get all counter sets in the file, type “Import-Counter -listset *”.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? true

    -MaxSamples <Int64>
        Specifies the maximum number of samples of each counter to import. By default, Get-Counter imports all of the data in the files specified by the Path parameter.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Path <string[]>
        Specifies the file paths of the files to be imported. This parameter is required.

        Enter the path and file name of a, .csv,, .tsv, or .blg file that you exported by using the Export-Counter cmdlet. You can specify only one .csv or .tsv file, but you can specify multiple .blg files (up to 32) in each command. You can also pipe file path strings (in quotation marks) to Import-Counter.

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? true

    -StartTime <DateTime>
        Imports only counter data with a timestamp greater than or equal to the specified date and time. Enter a DateTime object, such as one created by the Get-Date cmdlet. By default, Import-Counter imports all counter data in the files specified by the Path parameter.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Summary <switch>
        Gets a summary of the imported data, instead of getting individual counter data samples.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String
        You can pipe performance counter log paths to Import-Counter.

OUTPUTS
    Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet, Microsoft.PowerShell.Commands.GetCounter.CounterSet, Microsoft.PowerShell.Commands.GetCounter.CounterFileInfo
        By default, Import-Counter returns a Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet. If you use the ListSet parameter, Import-Command returns a Microsoft.PowerShell.Commands.GetCounter.CounterSet object. If you use the Summary parameter, Import-Command returns a Microsoft.PowerShell.Commands.GetCounter.CounterFileInfo object.

NOTES

        The Import-Counter cmdlet does not have a ComputerName parameter. However, if the computer is configured for Windows PowerShell remoting, you can use the Invoke-Command cmdlet to run an Import-Counter command on a remote computer.

    ————————– EXAMPLE 1 ————————–

    C:\PS># Import-Counter

    Description
    ———–
    This command imports all of the counter data from the ProcessorData.csv file into the $data Variable.

    C:\PS> $data = Import-Counter -Path ProcessorData.csv

    ————————– EXAMPLE 2 ————————–

    C:\PS># Import-Counter

    Description
    ———–
    This command imports only the Processor(_total)\Interrupts\sec counter data from the ProcessorData.blg file into the $i Variable.

    C:\PS> $i = Import-Counter -Path ProcessorData.blg -Counter “\\SERVER01\Processor(_Total)\Interrupts/sec”

    ————————– EXAMPLE 3 ————————–

    C:\PS># Import-Counter

    Description
    ———–
    This example shows how to select data from a performance counter log file (.blg) and then export the selected data to a .csv file.

    The first four commands get the counter paths from the file and save them in a Variable. The last two commands import selected data and then export only the selected data.

    The first command uses Import-Counter to import all of the performance counter data from the ProcessorData.blg files. The command saves the data in the $data Variable.

    C:\PS> $data = Import-Counter .\processordata.blg

    The second command displays the counter paths in the $data Variable. The display is shown in the command output.

    C:\PS> $data[0].countersamples | Format-Table path

    Path
    —-
    \\SERVER01\Processor(_Total)\DPC Rate
    \\SERVER01\Processor(1)\DPC Rate
    \\SERVER01\Processor(0)\DPC Rate
    \\SERVER01\Processor(_Total)\% Idle Time
    \\SERVER01\Processor(1)\% Idle Time
    \\SERVER01\Processor(0)\% Idle Time
    \\SERVER01\Processor(_Total)\% C3 Time
    \\SERVER01\Processor(1)\% C3 Time
    …

    The third command gets the counter paths that end in “Interrupts/sec” and saves the paths in the $IntCtrs Variable.

    C:\PS> $IntCtrs = $data[0].countersamples | where {$_.path -like “*interrupts/sec”} | foreach {$_.path}

    The fourth command displays the selected counter paths.

    C:\PS> $IntCtrs

    \\SERVER01\Processor(_Total)\Interrupts/sec
    \\SERVER01\Processor(1)\Interrupts/sec
    \\SERVER01\Processor(0)\Interrupts/sec

    The fifth command uses the Import-Counter cmdlet to import the data. It uses the Counter parameter with the $IntCtrs Variable to import only data for the counter paths in $IntCtrs.

    C:\PS> $i = Import-Counter -Path .\processordata.blg -Counter $intCtrs

    The sixth command uses the Export-Counter cmdlet to export the data.

    C:\PS> $i | Export-Counter -Path .\interrupts.csv -format CSV

    ————————– EXAMPLE 4 ————————–

    C:\PS># Import-Counter

    Description
    ———–
    This example shows how to display all the counter paths in a group of imported counter sets.

    The first command uses the ListSet parameter to get all of the counter sets that are represented in a counter data file.

    C:\PS> Import-Counter -Path processordata.csv -listset *

    CounterSetName     : Processor
    MachineName        : \\SERVER01
    CounterSetType     : MultiInstance
    Description        :
    Paths             : {\\SERVER01\Processor(*)\DPC Rate, \\SERVER01\Processor(*)\% Idle Time, \\SERVER01
                         \Processor(*)\% C3 Time, \\SERVER01\Processor(*)\% Interrupt Time…}
    PathsWithInstances : {\\SERVER01\Processor(_Total)\DPC Rate, \\SERVER01\Processor(1)\DPC Rate, \\SERVER01
                         \Processor(0)\DPC Rate, \\SERVER01\Processor(_Total)\% Idle Time…}
    Counter            : {\\SERVER01\Processor(*)\DPC Rate, \\SERVER01\Processor(*)\% Idle Time, \\SERVER01
                         \Processor(*)\% C3 Time, \\SERVER01\Processor(*)\% Interrupt Time…}

    The second command gets all of the counter paths from the list set.

    C:\PS> Import-Counter -Path processordata.csv -listset * | foreach {$_.paths}

    \\SERVER01\Processor(*)\DPC Rate
    \\SERVER01\Processor(*)\% Idle Time
    \\SERVER01\Processor(*)\% C3 Time
    \\SERVER01\Processor(*)\% Interrupt Time
    \\SERVER01\Processor(*)\% C2 Time
    \\SERVER01\Processor(*)\% User Time
    \\SERVER01\Processor(*)\% C1 Time
    \\SERVER01\Processor(*)\% Processor Time
    \\SERVER01\Processor(*)\C1 Transitions/sec
    \\SERVER01\Processor(*)\% DPC Time
    \\SERVER01\Processor(*)\C2 Transitions/sec
    \\SERVER01\Processor(*)\% Privileged Time
    \\SERVER01\Processor(*)\C3 Transitions/sec
    \\SERVER01\Processor(*)\DPCs Queued/sec
    \\SERVER01\Processor(*)\Interrupts/sec

    ————————– EXAMPLE 5 ————————–

    C:\PS># Import-Counter

    Description
    ———–
    This example imports only the counter data that has a time stamp between the starting an ending ranges specified in the command.

    The first command lists the time stamps of all of the data in the ProcessorData.blg file.

     C:\PS> Import-Counter -Path .\disk.blg | Format-Table timestamp

    The second and third commands save particular time stamps in the $start and $end Variables. The strings are cast to DateTime objects.

     C:\PS> $start = [datetime]”7/9/2008 3:47:00 PM”
     C:\PS> $end = [datetime]”7/9/2008 3:47:59 PM”

    The fourth command uses Import-Counter to get only counter data that has a time stamp between the start and end times (inclusive). The command uses the StartTime and EndTime parameters to specify the range.

     C:\PS> $t-data = Import-Counter -Path disk.blg -StartTime $start -EndTime $end

    ————————– EXAMPLE 6 ————————–

    C:\PS># Import-Counter

    Description
    ———–
    This example shows how to import the five oldest and five newest samples from a performance counter log file.

    The first command uses the Import-Counter cmdlet to import data from the Disk.blg file. The command uses the MaxSamples parameter to limit the import to five counter samples. This command gets the first (oldest) five samples in the file.

    C:\PS> Import-Counter -Path disk.blg -MaxSamples 5

    The second command uses array notation and the Windows PowerShell range operator (..) to get the last five counter samples from the file. These are the five newest samples.

    C:\PS> (Import-Counter -Path disk.blg)[-1 .. -5]

    ————————– EXAMPLE 7 ————————–

    C:\PS># Import-Counter

    Description
    ———–
    This command uses the Summary parameter to get a summary of the counter data from the Memory.blg file.

    C:\PS> Import-Counter D:\Samples\memory.blg -summary

    OldestRecord            NewestRecord            SampleCount
    ————            ————            ———–
    7/10/2008 2:59:18 PM    7/10/2008 3:00:27 PM    1000

    ————————– EXAMPLE 8 ————————–

    C:\PS># Import-Counter

    Description
    ———–
    This example updates a performance counter log file.

    The first command uses the ListSet parameter of Import-Counter to get the counters in OldData.blg, an existing counter log file. The command uses a pipeline operator (|) to send the data to a ForEach-Object command that gets only the values of the PathsWithInstances property of each object.

    C:\PS> $counters = Import-Counter olddata.blg -ListSet * | foreach {$_.PathsWithInstances}

    The second command uses those same counters in a new Get-Counter command to get a current sample, and export it to the NewData.blg file.

    C:\PS> Get-Counter -Counter $counters -MaxSamples 20 | Export-Counter c:\Logs\newdata.blg

    ————————– EXAMPLE 9 ————————–

    C:\PS># Import-Counter

    Description
    ———–
    This command imports performance log data from two logs and saves the data in the $counters Variable. The command uses a pipeline operator to send performance log paths to Import-Counter.

    C:\PS> $counters = “d:\test\pdata.blg”, “d:\samples\netlog.blg” | Import-Counter

    Notice that each path is enclosed in quotation marks and that the paths are separated from each other by a comma.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=138338
    Get-Counter
    Export-Counter

Get-Counter

NAME
    Get-Counter

SYNOPSIS
    Gets performance counter data from local and remote computers.

SYNTAX
    Get-Counter [-Counter] <string[]> [-ComputerName <string[]>] [-Continuous] [-MaxSamples <Int64>] [-SampleInterval <int>] [<CommonParameters>]

    Get-Counter -ListSet <string[]> [-ComputerName <string[]>] [<CommonParameters>]

DESCRIPTION
    The Get-Counter cmdlet gets live, real-time performance counter data directly from the performance monitoring instrumentation in Windows. You can use it to get performance data from the local or remote computers at the sample interval that you specify.

    Without parameters, a “Get-Counter” command gets counter data for a set of system counters.

    You can use the parameters of Get-Counter to specify one or more computers, to list the performance counter sets and the counters that they contain, and to set the sample size and interval.

PARAMETERS
    -ComputerName <string[]>
        Gets data from the specified computers. Type the NetBIOS name, an Internet Protocol (IP) address, or the fully qualified domain names of the computers. The default value is the local computer.

        Note: Get-Counter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-Counter even if your computer is not configured for remoting in Windows PowerShell.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Continuous [<SwitchParameter>]
        Gets samples continuously until you press CTRL+C. By default, Get-Counter gets only one counter sample. You can use the SampleInterval parameter to set the interval for continuous sampling.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Counter <string[]>
        Gets data from the specified performance counters. Enter one or more counter paths. Wildcards are permitted only in the Instance value. You can also pipe counter path strings to Get-Counter.

        Each counter path has the following format:
             “[\\<ComputerName>]\<CounterSet>(<Instance>)\<CounterName>”

        For example:
                “\\Server01\Processor(2)\% User Time”.

        The <ComputerName> element is optional. If you omit it, Get-Counter uses the value of the ComputerName parameter.

        Note: To get correctly formatted counter paths, use the ListSet parameter to get a performance counter set. The Paths and PathsWithInstances properties of each performance counter set contain the individual counter paths formatted as a string. You can save the counter path strings in a Variable or pipe the string directly to another Get-Counter command. For a demonstration, see the examples.

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? true

    -ListSet <string[]>
        Gets the specified performance counter sets on the computers. Enter the names of the counter sets. Wildcards are permitted. You can also pipe counter set names to Get-Counter.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? true

    -MaxSamples <Int64>
        Specifies the number of samples to get from each counter. The default is 1 sample. To get samples continuously (no maximum sample size), use the Continuous parameter.

        To collect a very large data set, consider running a Get-Counter command as a Windows PowerShell background job. For more information, see about_jobs and Start-Job.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -SampleInterval <int>
        Specifies the time between samples in seconds. The minimum value and the default value are 1 second.

        Required?                    false
        Position?                    named
        Default value                1
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String[]
        You can pipe counter paths and counter set (ListSet) names to Get-Counter.

OUTPUTS
    Microsoft.PowerShell.Commands.GetCounter.CounterSet, Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet, Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSample
        The ListSet parameter gets Microsoft.PowerShell.Commands.GetCounter.CounterSet objects. The Counter parameter gets Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet objects. Each counter value is a Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSample object.

NOTES

        Performance counters are often protected by access control lists (ACLs). To get all available performance counters, open Windows PowerShell with the “Run as administrator” option.

        By default, Get-Counter gets one sample during a one-second sample interval. To change this behavior, use the MaxSamples and Continuous parameters.

        The MaxSamples and SampleInterval values that you set apply to all the counters on all the computers in the command. To set different values for different counters, enter separate Get-Counter commands for each counter.

    ————————– EXAMPLE 1 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This command gets all of the counter sets on the local computer.

    C:\PS> Get-Counter -ListSet *

    Because many of the counter sets are protected by access control lists (ACLs), to see all counter sets, open Windows PowerShell with the “Run as administrator” option before using the Get-Counter command.

    ————————– EXAMPLE 2 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This command gets the current “% Processor Time” combined values for all processors on the local computer. It collects data every two seconds until it has three values.

    C:\PS> Get-Counter -Counter “\Processor(_Total)\% Processor Time” -SampleInterval 2 -MaxSamples 3

    ————————– EXAMPLE 3 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This command gets an alphabetically sorted list of the names of all of the counter sets on the local computer.

    C:\PS> Get-Counter -listset * | Sort-Object countersetname | Format-Table countersetname

    ————————– EXAMPLE 4 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    These commands use the Path property of a counter set to find the correctly formatted path names for the performance counters. You can use a command like this one to get the correct counter path names.

    The first command gets the path names of the performance counters in the Memory counter set on the local computer.

    C:\PS> (Get-Counter -listset memory).paths

    \Memory\Page Faults/sec
    \Memory\Available Bytes
    \Memory\Committed Bytes
    \Memory\Commit Limit
    \Memory\Write Copies/sec
    \Memory\Transition Faults/sec
    \Memory\Cache Faults/sec
    \Memory\Demand Zero Faults/sec
    \Memory\Pages/sec
    \Memory\Pages Input/sec
    …

    The second command gets the path names that include “cache”.

    C:\PS> (Get-Counter -listset memory).paths | where {$_ -like “*cache*”}

    \Memory\Cache Faults/sec
    \Memory\Cache Bytes
    \Memory\Cache Bytes Peak
    \Memory\System Cache Resident Bytes
    \Memory\Standby Cache Reserve Bytes
    \Memory\Standby Cache Normal Priority Bytes
    \Memory\Standby Cache Core Bytes

    ————————– EXAMPLE 5 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    These commands get the Disk Reads/sec counter data from the Server01 and Server02 computers.

    The first command saves the Disk Reads/sec counter path in the $diskreads Variable.

    C:\PS> $diskreads = “\LogicalDisk(C:)\Disk Reads/sec”

    The second command uses a pipeline operator (|) to send the counter path in the $diskreads Variable to the Get-Counter cmdlet. The command uses the MaxSamples parameter to limit the output to 10 samples.

    C:\PS> $diskreads | Get-Counter -computer Server01, Server02 -MaxSamples 10

    ————————– EXAMPLE 6 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This command gets the correctly formatted path names for the PhysicalDisk performance counters, including the instance names.

    C:\PS> (Get-Counter -list physicaldisk).pathswithinstances

    ————————– EXAMPLE 7 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    These commands get the value of the “% DPC Time” performance counter on 50 randomly select computers in the enterprise.

    The first command uses the Get-Content cmdlet to get the list of enterprise servers from the Servers.txt file. It uses the Get-Random cmdlet to select 50 server names randomly from the Servers.txt file contents. The results are saved in the $servers Variable.

    C:\PS> $servers = Get-Random (Get-Content servers.txt) -count 50

    The second command saves the counter path to the “% DPC Time” cmdlet in the $Counter Variable. The counter path includes a wildcard character in the instance name to get the data on all of the processors on each of the computers.

    C:\PS> $counter = “\Processor(*)\% DPC Time”

    The third command uses the Get-Counter cmdlet to get the counter values. It uses the Counter parameter to specify the counters and the ComputerName parameter to specify the computers saved in the $servers Variable.

    C:\PS> Get-Counter -Counter $counter -ComputerName $servers

    ————————– EXAMPLE 8 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    These commands get a single value for all of the performance counters in the memory counter set on the local computer.

    The first command gets the counter paths and saves them in the $memCounters Variable.

    C:\PS> $memCounters = (Get-Counter -list memory).paths

    The second command uses the Get-Counter cmdlet to get the counter data for each counter. It uses the Counter parameter to specify the counters in $memCounters.

    C:\PS> Get-Counter -Counter $memCounters

    ————————– EXAMPLE 9 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This example shows the property values in the PerformanceCounterSample object that represents each data sample.

    The first command saves a counter path in the $counter Variable.

    C:\PS> $counter = “\\SERVER01\Process(Idle)\% Processor Time”

    The second command uses the Get-Counter cmdlet to get one sample of the counter values. It saves the results in the $data Variable.

    C:\PS> $data = Get-Counter $counter

    The third command uses the Format-List cmdlet to display all the properties of the CounterSamples property of the sample set object as a list.

    C:\PS> $data.countersamples | Format-List -property *

    Path             : \\SERVER01\process(idle)\% processor time
    InstanceName     : idle
    CookedValue     : 198.467899571389
    RawValue         : 14329160321003
    SecondValue     : 128606459528326201
    MultipleCount    : 1
    CounterType     : Timer100Ns
    Timestamp        : 7/15/2008 6:39:12 PM
    Timestamp100NSec : 128606207528320000
    Status         : 0
    DefaultScale     : 0
    TimeBase         : 10000000

    You can use the properties of the CounterSamples object to examine, select, sort, and group the data.

    ————————– EXAMPLE 10 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    The command runs a Get-Counter command as background job. For more information, see Start-Job.

    C:\PS> $counters = “\LogicalDisk(_Total)\% Free Space”

    C:\PS> Start-Job -scriptblock {Get-Counter -Counter $counters -MaxSamples 1000)

    ————————– EXAMPLE 11 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This command uses the Get-Counter and Get-Random cmdlets to find the percentage of free disk space on 50 computers selected randomly from the Servers.txt file.

    C:\PS> Get-Counter -ComputerName (Get-Random servers.txt -count 50) -Counter “\LogicalDisk(*)\% Free Space”

    ————————– EXAMPLE 12 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This example shows how to associate counter data with the computer on which it originated, and how to manipulate the data.

    The first command uses the Get-Counter cmdlet to get the “LogicalDisk\% Free Space” counter value from two remote computers, S1 and S2. It saves the result in the $a Variable.

    $a = Get-Counter “\LogicalDisk(_Total)\% Free Space” -comp s1, s2

    The second command displays the results in the $a Variable. All of the data is stored in the object, but it is not easy to see it in this form.

    C:\PS> $a

    Counter Paths: \\s1\\logicaldisk(c:)\% free space, \\s1\\logicaldisk(d:)\% free space, \\s1\\logicaldisk(_total)\% free space, \\s2\\logicaldisk(c:)\% free space, \\s2\\logicaldisk(_total)\% free space

    Timestamp     : 7/15/2008 5:09:08 PM
    Cooked Values : “0.327058823529412”, “17.8952248493278”, “12.9994033060778”, “75.0754805595626”, “75.0754805595626”

    The third command displays in a table the value of the CounterSamples property of the PerformanceCounterSampleSet object that Get-Counter returns. (To see all of the properties and methods of the object, pipe it to the Get-Member cmdlet.)

    C:\PS> $a.countersamples | Format-Table -auto

    Path                                     InstanceName     CookedValue
    —-                                     ————     ———–
    \\s1\\logicaldisk(c:)\% free space     c:         0.327058823529412
    \\s1\\logicaldisk(d:)\% free space     d:            17.8952248493278
    \\s1\\logicaldisk(_total)\% free space _total        12.9994033060778
    \\s2\\logicaldisk(c:)\% free space     c:            75.0754805595626
    \\s2\\logicaldisk(_total)\% free space _total        75.0754805595626

    The CounterSamples property contains a PerformanceCounterSample object with its own properties and methods. The fourth command uses array notation to get the first counter sample and a pipeline operator to send the counter sample object to the Format-List cmdlet, which displays all of its properties and methods in a list. This display shows the richness of the data in each counter sample object.

    The fourth command shows how to select data from the counter samples. It uses the Where-Object cmdlet to get only the counter samples with a CookedValue of less than 15.

    C:\PS> $a.countersamples | where {$_.cookedvalue -lt 15}

    Path                                     InstanceName     CookedValue
    —-                                     ————     ———–
    \\s1\\logicaldisk(c:)\% free space     c:         0.327058823529412
    \\s1\\logicaldisk(_total)\% free space _total        12.9994033060778

    ————————– EXAMPLE 13 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This example shows how to sort the performance counter data that you retrieve. The example finds the processes on the computer that are using the most processor time during the sampling.

    The first command gets the “Process\% Processor Time” counter for all the processes on the computer. The command saves the results in the $p Variable.

    C:\PS> $p = Get-Counter ‘\Process(*)\% Processor Time’

    The second command gets the CounterSamples property of the sample set object in $p and it sorts the samples in descending order based on the cooked value of the sample. The command uses the Format-Table cmdlet and its AutoFormat parameter to position the columns in the table.

    C:\PS> $p.CounterSamples | Sort-Object -property CookedValue -Descending | Format-Table -auto

    Path                                             InstanceName     CookedValue
    —-                                             ————     ———–
    \\server01\process(_total)\% processor time        _total        200.00641042078
    \\server01\process(idle)\% processor time         idle         200.00641042078
    \\server01\process(explorer#1)\% processor time    explorer                    0
    \\server01\process(dwm#1)\% processor time         dwm                         0
    \\server01\process(taskeng#1)\% processor time     taskeng                     0
    \\server01\process(taskhost#1)\% processor time    taskhost                    0
    \\server01\process(winlogon)\% processor time     winlogon                    0
    \\server01\process(csrss)\% processor time         csrss                     0

    ————————– EXAMPLE 14 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    These commands find the processes on the computer with the largest working sets. They list the processes in descending order based on their working set size.

    The first command gets one sample of the “Process\Working Set – Private” counter for each process. The command saves the counter data in the $ws Variable.

    C:\PS> $ws = Get-Counter “\Process(*)\Working Set – Private”

    The second command uses a pipeline operator (|) to send the data in the CounterSamples property of the $ws Variable to the Sort-Object cmdlet, where the process data is sorted in descending order by the value of the CookedValue property. Another pipeline sends the sorted data to the Format-Table cmdlet, where the data is formatted as a table with InstanceName and CookedValue columns.

    C:\PS> $ws.countersamples | Sort-Object -property cookedvalue -descending | Format-Table -property InstanceName, CookedValue -auto

    InstanceName CookedValue
    ———— ———–
    _total         162983936
    svchost         40370176
    powershell     15110144
    explorer         14135296
    svchost         10928128
    svchost         9027584
    …

    ————————– EXAMPLE 15 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This command gets a series of samples of the Processor\% Processor Time counter at the default one second interval. To stop the command, press CTRL + C.

    C:\PS> Get-Counter -Counter “\processor(_total)\% processor time” -Continuous

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=138335
    Import-Counter
    Export-Counter