Solved

Create Powershell script from excel

Posted on 2013-07-02
4
827 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

679 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