Solved

Create Powershell script from excel

Posted on 2013-07-02
4
791 Views
Last Modified: 2013-07-04
example
hi folks

i like to create a powershell script with multiple lines as you can see in the excel picture above.
How can i write this cells with powershell code from excel to a ps1 file?
Then i like to call this ps1 from excel to execute embedded in vbs code

LaunchPowerShell.VBS
 
Set objShell = CreateObject("Wscript.shell")
 
objShell.run("powershell -noexit -file c:\fso\CleanupFiles.ps1")
0
Comment
Question by:Mandy_
  • 2
4 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39292813
hi again Mandy.
here's the code:

Private Sub CommandButton1_Click()
Counter = 19
Dim Stringstogether
Do
        Dim Command
        Command = Worksheets("ext2010").Cells(Counter, 2).Value
        Stringstogether = Stringstogether & Command & VbCrLf 
Loop Until Command = ""

Set fso = CreateObject("Scripting.FileSystemObject")

Set oFile = FSO.CreateTextFile(" c:\fso\CleanupFiles.ps1")
oFile.WriteLine Stringstogether 
oFile.Close

Set objShell = CreateObject("Wscript.shell")
 
objShell.run("powershell -noexit -file c:\fso\CleanupFiles.ps1")
End Sub

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39292829
change the counter to the first line where the commands starts.
btw, wouldn't be easier to simple copy all the commands from the excel and create the PS file yourself?
0
 
LVL 2

Author Comment

by:Mandy_
ID: 39292925
hi ,

yes what i want is this

Topic

i'm still not have time enough to try different setups. how could i start all commands in only one ps session (EWS) ?
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

25 Experts available now in Live!

Get 1:1 Help Now