+ Reply to Thread
Results 1 to 3 of 3

Create button to run PowerShell scripts, return output to cell

  1. #1
    Registered User
    Join Date
    10-01-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Create button to run PowerShell scripts, return output to cell

    Hi all, I've searched the forum for what I'm trying to do but didn't find anything really relevant. Here's what I'm trying to accomplish:

    Every month I manually fill-in an Excel document about key information spread across several servers. This information includes disk space utilization of certain folders, number of antivirus agents installed at a given client location, spam filtering accounts active, etc. Eventually, I want to find a way to gather this information in each section by pressing a button and having Excel execute the necessary commands/queries against these systems. Pursuant to that, I'm starting by trying to create a button that will run a PowerShell script in a given column. I've already built this script (which is designed to run against a remote server) and tested it, I just need to get Excel to run the PS script and return the result to the cell. I know that Excel does this natively via VBscript, and if this isn't possible, can I convert easily from PowerShell to VB?

    Thanks much in advance,


    Chip

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Create button to run PowerShell scripts, return output to cell

    When running manually from a command window, where does your script output the data it gathers? If it outputs the data to the command window then you could have Excel VBA run the script, redirecting the output to a file, wait for the script to finish and then read the data from the file. The Windows Script Host Run method (http://msdn.microsoft.com/en-us/libr...=vs.84%29.aspx) can do the first 3 steps, and then use VBA Open and Input #, Line Input # statements or FSO methods to read the data from the file. I've not used PowerShell, but it should be something like the following:
    Please Login or Register  to view this content.
    The "%comspec% /c " & part might not be needed.
    Post responsibly. Search for excelforum.com

  3. #3
    Registered User
    Join Date
    10-01-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Create button to run PowerShell scripts, return output to cell

    The script outputs the data with correct formatting to the shell. However, the only snag might be that the script, at only one point, is interactive in that it must prompt for a password to be used to execute the PowerShell cmdlet on a remote server. I chose to do this rather than put the password as plain text in the script, and then have to worry about a layer of security on the Excel file. If you or anyone else have alternatives, I'm totally open. Chippy, I'll have to look into your suggestion as I'm not VB savvy.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1