Solved

Invoke-Expression to output and variable

Posted on 2013-11-18
2
669 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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