Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 476 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running a PS1 script using a batch file (.bat)

#1
Currently the following is my path for launching the VMware vSphere PowerCLI command prompt. I wish to run my `sample.ps1` script automatically using a batch file. How can I incoporate `sample.ps1` into this path and create a batch file?

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -c ". \"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\""
Reply

#2
If you are working with PowerShell 2.0, you can use the `-file` parameter of PowerShell.exe

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -file "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"

If you are working with PowerShell 1.0, you can use -command parameter this way

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -command "& 'C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'"
Reply

#3
echo off

Title,Report Script &color 9e
for /f "usebackq delims=$" %%a in (`cd`) do (
set SCRIPTDIR=%%a
)

(Set ScriptFile=%SCRIPTDIR%\Report.ps1)

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -c ". \"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\";%ScriptFile%"



Reply

#4
You can use this to launch arbitrary .ps1 scripts via .bat files by calling the bat file like your ps1. Then extract the name of file in batch and call powershell with it.

For a ready to use solution, use the following Gist:
Reply

#5
I saw this code in another page, I test it in a W2012 R2 and it runs.

I hope it work:

C:\>powershell "C:\>1\file.ps1"
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through