powershell - Table - Count Column


I have a PowerShell script that coverts JSON from an API and creates a table output. How would I TOTAL (add or count) the column 'TotalEndpoints' and display the total number of Enpoints?

Here is the creation of the table

(Invoke-RestMethod @Params).Sites | Format-Table SiteName,SiteId,TotalEndpoints

Output of Powershell script

3 Answers: 

Use Select-Object for manipulating objects. Use Format-Table only as the last step for the actual output.

$sites = (Invoke-RestMethod @Params).Sites |
         Select-Object SiteName, SiteId, TotalEndpoints

$total = @($sites | Select-Object -Expand TotalEndpoints).Count

$sites | Format-Table
"Total: $total"

Was able to figure it out.

$value = 0
$t = foreach($Sites in $test)
$value = $value + $Sites.TotalEndpoints
Write-Host $value

Your loop will get the job done. You can also try Measure-Object if you want to avoid duplicating for-loops for common calculations.

Try something like this:

$siteData = (Invoke-RestMethod @Params).Sites
$siteData | Format-Table SiteName,SiteId,TotalEndpoints
$GrandTotalEndpoints = ($siteData | Measure-Object -sum -property TotalEndpoints).Sum
Write-Host $GrandTotalEndpoints

More Articles

python - Heap that supports modification of its elements?

Here is my scenario. I want to implement A* (in Python) without having to resort to linear-time min or in operations. I need a heap to be able to efficiently get the lowest weight item. My immediate response was 'Easy! I'll use heapq!' Then I discovered that life is rarely as simple as we would like

java - gRPC: Generate certificateChainFile and privateKeyFile to make TLS/SSL work

I want to make tls/ssl connection between client and server(Not mutual, one way). This is my setup:Server: Server server = ServerBuilder.forPort(8443) // Enable TLS .useTransportSecurity(certChainFile, privateKeyFile) .addService(new GreetingServiceImpl()) .build();Cli

r - split string at every character

I want to split every character in a string and output it as comma or tab separated characters:I need to use file_in and file_out since I have very many lines.inputTTTGGCTTTGTGCAATGG........outputT,T,T,G,G,CT,T,T,GT,G,C,A,A,T,G,GI have used this, but it prints every character vertically: /usr/bin/p

libgit2sharp: how to set multiple values with same key

how do I set multiple values for a config-key? Some sections supports multiple values:[remote "origin"] url = git@github.com:schacon/simplegit-progit.git fetch = +refs/heads/master:refs/remotes/origin/master fetch = +refs/heads/qa/*:refs/remotes/origin/qa/*Something like this is not working in

Know of any setup tutorials for SQL Server Express and C#?

I'm a C# and MySQL developer, but I'm looking into Microsoft's SQL Server for a new project. I'm familiar with MySQL syntax and the .NET connector. Does anyone know of any decent tutorials that just cover the code to interact with SQL Server? No C# basics or SQL basics, just how to get the two tec

c++ - GCC Cross compile to a i586 architecture (Vortex86DX)

I have Ubuntu 12.01 with gcc 4.8.2 and would like to cross compile for the Vortex86DX CPU running an old 2.6.23 kernel.I´m trying the following testing code:#include <iostream>int main(){ std::cout << "Hello world" << std::endl;}That is compiled using the following command line:g

Using gstreamer plugins bad in android

I am trying to show h264 encodes streams inside an android application using the GStreamer SDK and Android NDK. My Android.mk looks like:LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := AppLOCAL_SRC_FILES := App.cppLOCAL_SHARED_LIBRARIES := gstreamer_androidLOCAL_LDLIBS := -llog -

c++ - How To Return Elapsed Time From steady_clock as a Primitive Data Type (double)

First and foremost, let me say that I just starting using this library yesterday, so my understanding of it is still fairly basic. I'm trying to capture the FPS of a vision processing program I'm creating and output it to a screen using the chrono library. In my case, I need to cast the elapsed time

hashtable - Powershell 2 and .NET: Optimize for extremely large hash tables?

I am dabbling in Powershell and completely new to .NET.I am running a PS script that starts with an empty hash table. The hash table will grow to at least 15,000 to 20,000 entries. Keys of the hash table will be email addresses in string form, and values will be booleans. (I simply need to track whe

Missing plugin for GStreamer for Android SDK

I changed the stream url in the included Tutorial 5 (a basic media player) to a h.264/mp3 media stream (from its original ogv stream) and it started complaining about some missing plugins.After doing some googling I found Prajnashi's gst-ffmpeg plugin for Android https://github.com/prajnashi/gst-ffm