Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create Powershell script from excel

Posted on 2013-07-02
4
Medium Priority
?
873 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:
Meir Rivkin earned 1500 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:Meir Rivkin
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

971 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