Avatar of tonelm54
tonelm54

asked on 

Invoke-Expression to output and variable

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
Powershell

Avatar of undefined
Last Comment
BT15
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of BT15
BT15
Flag of United States of America image

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.
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo