Solved

Invoke-Expression to output and variable

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

Accepted Solution

by:
footech earned 500 total points
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now