Solved

Invoke-Expression to output and variable

Posted on 2013-11-18
2
700 Views
Last Modified: 2013-12-05
Is it possible to echo out the result of a command to the screen and variable?

What I want to do it run a chkdsk command, showing the user progress of the chkdsk but at the end storing the output result into a variable so I can email that variable along with other variables throughout the script?

Thank you
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39656995
Have a look at Tee-Object with the -variable parameter.
However, depending on the script, this may not be sufficient.  Sometimes you just have to create an array and add objects to it.  This method is very flexible, but it all kind of depends.
0
 
LVL 7

Expert Comment

by:BT15
ID: 39660736
just tested this and it works. Granted, you will have to jump through the hoops of enabling PSRemoting.

$results = Invoke-Command -ComputerName $computername -ScriptBlock {chkdsk c:}

$results

Open in new window


EDIT: Nevermind... this doesn't accomplish the Realtime monitoring that you requested
EDIT: Double Nevermind... you weren't asking to do this on remote machines anyway.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question