• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 879
  • Last Modified:

Create Powershell script from excel

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
Mandy_
Asked:
Mandy_
  • 2
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
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
 
Meir RivkinFull stack Software EngineerCommented:
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
 
Mandy_Author Commented:
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

Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now