Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:26:37+00:00 2026-06-02T08:26:37+00:00

I have a basic script that I want to improve so it goes off

  • 0

I have a basic script that I want to improve so it goes off and collects perfmon counters as Jobs instead of what I am currently doing (which is centrally retrieving counters).

The problem is, when I run Get-Counter in a Job in Powershell, the data that comes back can’t be inspected/used properly. I think it’s because it serializes the data.

This is my script, pretty basic:

Start-Job -ScriptBlock {$Counter = Get-Counter "\LogicalDisk(C:)\% Free Space" -MaxSamples 1 -SampleInterval 1 ; return $Counter}

do
{
    [array]$JobCount = Get-Job -State "Completed"
    $JobResults = Get-Job | Receive-Job

    if ($JobCount.Count -gt 0)
    {
        Write-Host "Job Completed"
    }
    else
    {
        Write-Host "Sleeping 1 Second..."
        Start-Sleep 1
    }
}
while ($JobCount.Count -lt 0)

$JobResults.CounterSamples

$JobResults.CounterSamples returns a string which says “Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSample”. That is the data type of the counter objects.

If I run this outside of a job it returns just fine:

$Counter = Get-Counter "\LogicalDisk(C:)\% Free Space" -MaxSamples 1 -SampleInterval 1
$Counter.CounterSamples

Anyone know how I can use the data within the Job results properly?

Still not had the answer I am looking for on this, any ideas people?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:26:40+00:00Added an answer on June 2, 2026 at 8:26 am

    I found a way around this myself, and it was basically to process the Countersamples in the job itself rather than try to pass the results back for processing:

    $ScriptBlock = {
    
        param
        (
            $Server,
            $ExportCSV
        )
    
        $Counter = Get-Counter -ComputerName $Server "LogicalDisk(C:)\% Free Space" -MaxSamples 10 -SampleInterval 2
        $CounterSamples = $Counter | % {$_.CounterSamples}
    
        $MasterArray = @()
        foreach ($CounterSample in $CounterSamples)
        {
            $TempArray = @()
            $TempArray = "" | Select Server, ObjectName, CounterName, InstanceName, Value, DateTime
    
            $Split = $CounterSample.Path.Remove(0,2)
            $Split = $Split.Split("\")
    
            $TempArray.Server = $Split[0]
            $TempArray.ObjectName = $Split[1].Split("(")[0]
            $TempArray.CounterName = $Split[2]
            $TempArray.InstanceName = $CounterSample.InstanceName
            $TempArray.Value = $CounterSample.CookedValue
            $TempArray.DateTime = $CounterSample.TimeStamp.ToString("yyyy-MM-dd HH:mm:ss")
    
            $MasterArray += $TempArray
        }
    
        $MasterArray | Export-Csv $ExportCSV -NoType
    }
    
    $Servers = "CHRIS-PC"
    
    foreach ($Server in $Servers)
    {
        $ExportCSVFile = "C:\Temp\$Server" + "_Samples.csv"
        Start-Job -ScriptBlock $ScriptBlock -ArgumentList @($Server, $ExportCSVFile)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic script that calculates and changes the width of a
I have a PHP script that does basic encryption of a string through the
I have a (very) basic validation script. I basically want to check for any
I have a basic greasemonkey script shown below, in which I want to run
I have a very basic python script that does HTTP connection. import socket def
I have a script that displays job listings, it currently displays (0) if there
I have written a basic script for the mail functionality. I am trying to
I have a basic PHP script. $hike_id = $_REQUEST['hike_id']; $height = $_REQUEST['height']; $width =
Hi I have this basic random quote script, but I would like it to
I have the basic jQueryUI progress bar code here; <script> $(function() { $(#progressbar).progressbar({ value:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.