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 5948315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:05:24+00:00 2026-05-22T17:05:24+00:00

I am writing a script where I would like to spit out a bunch

  • 0

I am writing a script where I would like to spit out a bunch of records and then display the count as the last line. This is what I have so far:

Get-Whatever -Department $Deparment
Write-Host (Get-Whatever -Department $Deparment).Count " records found"

But i’m curious if there is a way to do it without executing it twice. I thought that I had read you could use $$ somewhere but this isn’t working. Is there a better way to do this, or do I just have to run it twice?

My Desired output would look something like this:

Name
-------
Abe
Joe
Bill

3 records found
  • 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-05-22T17:05:25+00:00Added an answer on May 22, 2026 at 5:05 pm

    Why don’t you simply assign the result to a variable?

    $d = @(Get-Whatever -dep $department); $d
    Write-Host $d.Count records found
    

    Note the @(..). It ensures that even when Get-Whatever doesn’t return anything, $d will be empty array.

    Other way is e.g. Tee-Object. However, it somewhat “magically” creates variables, so it is not as readable as the first approach:

    Get-ChildItem | Tee-Object -var items
    Write-Host $items.Count items found
    

    As for Tee-Object (from documentation, try help tee-object -online):

    The Tee-Object cmdlet sends the output
    of a command in two directions (like
    the letter “T”). It stores the output
    in a file or variable and also sends
    it down the pipeline. If Tee-Object is
    the last command in the pipeline, the
    command output is displayed in the
    console.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Perl script and would like to use a n-ary tree data
I'm writing a Ruby script and would like to use a n-ary tree data
I'm currently writing a configure script for a library and would like to package
I would like to real-hand experienced answer on this. Which one is faster? Writing
I'm writing a PHP script and would like to present a warning message if
I'm writing a rake script and would like to detect (using Ruby rather than
I am writing a script that uses a temporary directory, and I would like
I am writing a bash script that modifies a file that looks like this:
I'm writing a python script which I would like to be able to both
I'm writing a form validation script and would like to validate a given field

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.