Writing and executing a powershell script with batchHow can I pass arguments to a batch file?Split long commands in multiple lines through Windows batch fileHow to sleep for 5 seconds in a batch file/cmd?Determine installed PowerShell versionTerminating a script in PowerShellHow to run a PowerShell scriptPowerShell says “execution of scripts is disabled on this system.”How do you comment out code in PowerShell?How to “comment-out” (add comment) in a batch/cmd?Powershell on Visual Studio Team Services operation requires an interactive window station

Is it possible for a vehicle to be manufactured without a catalytic converter?

Specific use case of to_address

A word that means "blending into a community too much"

Why am I Seeing A Weird "Notch" on the Data Line For Some Logical 1s?

Whats the meaning of enp#s#f#?

Can I utilise a baking stone to make crepes?

Who won a Game of Bar Dice?

Does Assassinate grant two attacks?

Return a String containing only alphabets without spaces

I have a problematic assistant manager, but I can't fire him

Which languages would be most useful in Europe at the end of the 19th century?

Live action TV show where High school Kids go into the virtual world and have to clear levels

How to hide rifle during medieval town entrance inspection?

Are there any normal animals in Pokemon universe?

Equivalent of "so much (as that)" in this context?

What aircraft was used as Air Force One for the flight between Southampton and Shannon?

Is there a set of positive integers of density 1 which contains no infinite arithmetic progression?

How to make insert mode mapping count as multiple undos?

Why can I traceroute to this IP address, but not ping?

I've been given a project I can't complete, what should I do?

Error 57 when installing Liquidity

Why are MBA programs closing?

Is it possible to fly backward if you have REALLY STRONG headwind?

My boss want to get rid of me - what should I do?



Writing and executing a powershell script with batch


How can I pass arguments to a batch file?Split long commands in multiple lines through Windows batch fileHow to sleep for 5 seconds in a batch file/cmd?Determine installed PowerShell versionTerminating a script in PowerShellHow to run a PowerShell scriptPowerShell says “execution of scripts is disabled on this system.”How do you comment out code in PowerShell?How to “comment-out” (add comment) in a batch/cmd?Powershell on Visual Studio Team Services operation requires an interactive window station






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm trying to make a standalone batch file that automates the process of setting up a server for the game "Killing Floor 2." To do this, I need to create then execute a PowerShell script to gain access to the resources I need. So far I have this



@echo off
del script.ps1
(echo $url = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip") >> script.ps1
(echo $output = "$PSScriptRootsteamcmd.zip") >> script.ps1
(echo $start_time = Get-Date) >> script.ps1
(echo $wc = New-Object System.Net.WebClient) >> script.ps1
(echo (New-Object System.Net.WebClient).DownloadFile($url, $output)) >> script.ps1
(echo Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)") >> script.ps1
(echo Add-Type -AssemblyName System.IO.Compression.FileSystem) >> script.ps1
(echo function Unzip) >> script.ps1
(echo ) >> script.ps1
(echo param([string]$zipfile, [string]$outpath)) >> script.ps1
(echo [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)) >> script.ps1
(echo ) >> script.ps1
(echo Unzip "$output" "$PSScriptRoot") >> script.ps1
PowerShell.exe -NoProfile -Command "& Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File script.ps1 -Verb RunAs'"
timeout /t 5
SteamCmd +login anonymous +force_install_dir ./kf2_ds +app_update 232130 +exit
cd kf2_ds
start kf2server.bat


However, during the write of the PowerShell script, I get the following error



.DownloadFile($url was unexpected at this time.


Any ideas on how to make this work or a better way to accomplish this?










share|improve this question



















  • 1





    You might be interested in a Batch + PowerShell hybrid format, rather than trying to battle with a ton of echoes and creating a temporary .ps1 script. This post demonstrates my preferred method. On a side note, why are you defining $wc but never using it?

    – rojo
    Nov 7 '16 at 3:26











  • $wc was left over from a previous version of the script. Thanks for pointing it out so I remembered to remove it.

    – Will Fetzer
    Nov 7 '16 at 4:30











  • Without being critical but curiosity,, why not call directly a PowerShell script with argument? It would be easier to debug no?

    – Esperento57
    Nov 7 '16 at 7:08











  • @Esperento57 It's because I need to automate the process into one file

    – Will Fetzer
    Nov 24 '16 at 2:07











  • A script powershell that writes in a powershell script and execute powershell.exe it works, all in one file :) But that's your choice. Good day to you.

    – Esperento57
    Nov 24 '16 at 6:37

















1















I'm trying to make a standalone batch file that automates the process of setting up a server for the game "Killing Floor 2." To do this, I need to create then execute a PowerShell script to gain access to the resources I need. So far I have this



@echo off
del script.ps1
(echo $url = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip") >> script.ps1
(echo $output = "$PSScriptRootsteamcmd.zip") >> script.ps1
(echo $start_time = Get-Date) >> script.ps1
(echo $wc = New-Object System.Net.WebClient) >> script.ps1
(echo (New-Object System.Net.WebClient).DownloadFile($url, $output)) >> script.ps1
(echo Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)") >> script.ps1
(echo Add-Type -AssemblyName System.IO.Compression.FileSystem) >> script.ps1
(echo function Unzip) >> script.ps1
(echo ) >> script.ps1
(echo param([string]$zipfile, [string]$outpath)) >> script.ps1
(echo [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)) >> script.ps1
(echo ) >> script.ps1
(echo Unzip "$output" "$PSScriptRoot") >> script.ps1
PowerShell.exe -NoProfile -Command "& Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File script.ps1 -Verb RunAs'"
timeout /t 5
SteamCmd +login anonymous +force_install_dir ./kf2_ds +app_update 232130 +exit
cd kf2_ds
start kf2server.bat


However, during the write of the PowerShell script, I get the following error



.DownloadFile($url was unexpected at this time.


Any ideas on how to make this work or a better way to accomplish this?










share|improve this question



















  • 1





    You might be interested in a Batch + PowerShell hybrid format, rather than trying to battle with a ton of echoes and creating a temporary .ps1 script. This post demonstrates my preferred method. On a side note, why are you defining $wc but never using it?

    – rojo
    Nov 7 '16 at 3:26











  • $wc was left over from a previous version of the script. Thanks for pointing it out so I remembered to remove it.

    – Will Fetzer
    Nov 7 '16 at 4:30











  • Without being critical but curiosity,, why not call directly a PowerShell script with argument? It would be easier to debug no?

    – Esperento57
    Nov 7 '16 at 7:08











  • @Esperento57 It's because I need to automate the process into one file

    – Will Fetzer
    Nov 24 '16 at 2:07











  • A script powershell that writes in a powershell script and execute powershell.exe it works, all in one file :) But that's your choice. Good day to you.

    – Esperento57
    Nov 24 '16 at 6:37













1












1








1








I'm trying to make a standalone batch file that automates the process of setting up a server for the game "Killing Floor 2." To do this, I need to create then execute a PowerShell script to gain access to the resources I need. So far I have this



@echo off
del script.ps1
(echo $url = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip") >> script.ps1
(echo $output = "$PSScriptRootsteamcmd.zip") >> script.ps1
(echo $start_time = Get-Date) >> script.ps1
(echo $wc = New-Object System.Net.WebClient) >> script.ps1
(echo (New-Object System.Net.WebClient).DownloadFile($url, $output)) >> script.ps1
(echo Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)") >> script.ps1
(echo Add-Type -AssemblyName System.IO.Compression.FileSystem) >> script.ps1
(echo function Unzip) >> script.ps1
(echo ) >> script.ps1
(echo param([string]$zipfile, [string]$outpath)) >> script.ps1
(echo [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)) >> script.ps1
(echo ) >> script.ps1
(echo Unzip "$output" "$PSScriptRoot") >> script.ps1
PowerShell.exe -NoProfile -Command "& Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File script.ps1 -Verb RunAs'"
timeout /t 5
SteamCmd +login anonymous +force_install_dir ./kf2_ds +app_update 232130 +exit
cd kf2_ds
start kf2server.bat


However, during the write of the PowerShell script, I get the following error



.DownloadFile($url was unexpected at this time.


Any ideas on how to make this work or a better way to accomplish this?










share|improve this question
















I'm trying to make a standalone batch file that automates the process of setting up a server for the game "Killing Floor 2." To do this, I need to create then execute a PowerShell script to gain access to the resources I need. So far I have this



@echo off
del script.ps1
(echo $url = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip") >> script.ps1
(echo $output = "$PSScriptRootsteamcmd.zip") >> script.ps1
(echo $start_time = Get-Date) >> script.ps1
(echo $wc = New-Object System.Net.WebClient) >> script.ps1
(echo (New-Object System.Net.WebClient).DownloadFile($url, $output)) >> script.ps1
(echo Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)") >> script.ps1
(echo Add-Type -AssemblyName System.IO.Compression.FileSystem) >> script.ps1
(echo function Unzip) >> script.ps1
(echo ) >> script.ps1
(echo param([string]$zipfile, [string]$outpath)) >> script.ps1
(echo [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)) >> script.ps1
(echo ) >> script.ps1
(echo Unzip "$output" "$PSScriptRoot") >> script.ps1
PowerShell.exe -NoProfile -Command "& Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File script.ps1 -Verb RunAs'"
timeout /t 5
SteamCmd +login anonymous +force_install_dir ./kf2_ds +app_update 232130 +exit
cd kf2_ds
start kf2server.bat


However, during the write of the PowerShell script, I get the following error



.DownloadFile($url was unexpected at this time.


Any ideas on how to make this work or a better way to accomplish this?







powershell batch-file






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 '16 at 3:12







Will Fetzer

















asked Nov 7 '16 at 3:03









Will FetzerWill Fetzer

83




83







  • 1





    You might be interested in a Batch + PowerShell hybrid format, rather than trying to battle with a ton of echoes and creating a temporary .ps1 script. This post demonstrates my preferred method. On a side note, why are you defining $wc but never using it?

    – rojo
    Nov 7 '16 at 3:26











  • $wc was left over from a previous version of the script. Thanks for pointing it out so I remembered to remove it.

    – Will Fetzer
    Nov 7 '16 at 4:30











  • Without being critical but curiosity,, why not call directly a PowerShell script with argument? It would be easier to debug no?

    – Esperento57
    Nov 7 '16 at 7:08











  • @Esperento57 It's because I need to automate the process into one file

    – Will Fetzer
    Nov 24 '16 at 2:07











  • A script powershell that writes in a powershell script and execute powershell.exe it works, all in one file :) But that's your choice. Good day to you.

    – Esperento57
    Nov 24 '16 at 6:37












  • 1





    You might be interested in a Batch + PowerShell hybrid format, rather than trying to battle with a ton of echoes and creating a temporary .ps1 script. This post demonstrates my preferred method. On a side note, why are you defining $wc but never using it?

    – rojo
    Nov 7 '16 at 3:26











  • $wc was left over from a previous version of the script. Thanks for pointing it out so I remembered to remove it.

    – Will Fetzer
    Nov 7 '16 at 4:30











  • Without being critical but curiosity,, why not call directly a PowerShell script with argument? It would be easier to debug no?

    – Esperento57
    Nov 7 '16 at 7:08











  • @Esperento57 It's because I need to automate the process into one file

    – Will Fetzer
    Nov 24 '16 at 2:07











  • A script powershell that writes in a powershell script and execute powershell.exe it works, all in one file :) But that's your choice. Good day to you.

    – Esperento57
    Nov 24 '16 at 6:37







1




1





You might be interested in a Batch + PowerShell hybrid format, rather than trying to battle with a ton of echoes and creating a temporary .ps1 script. This post demonstrates my preferred method. On a side note, why are you defining $wc but never using it?

– rojo
Nov 7 '16 at 3:26





You might be interested in a Batch + PowerShell hybrid format, rather than trying to battle with a ton of echoes and creating a temporary .ps1 script. This post demonstrates my preferred method. On a side note, why are you defining $wc but never using it?

– rojo
Nov 7 '16 at 3:26













$wc was left over from a previous version of the script. Thanks for pointing it out so I remembered to remove it.

– Will Fetzer
Nov 7 '16 at 4:30





$wc was left over from a previous version of the script. Thanks for pointing it out so I remembered to remove it.

– Will Fetzer
Nov 7 '16 at 4:30













Without being critical but curiosity,, why not call directly a PowerShell script with argument? It would be easier to debug no?

– Esperento57
Nov 7 '16 at 7:08





Without being critical but curiosity,, why not call directly a PowerShell script with argument? It would be easier to debug no?

– Esperento57
Nov 7 '16 at 7:08













@Esperento57 It's because I need to automate the process into one file

– Will Fetzer
Nov 24 '16 at 2:07





@Esperento57 It's because I need to automate the process into one file

– Will Fetzer
Nov 24 '16 at 2:07













A script powershell that writes in a powershell script and execute powershell.exe it works, all in one file :) But that's your choice. Good day to you.

– Esperento57
Nov 24 '16 at 6:37





A script powershell that writes in a powershell script and execute powershell.exe it works, all in one file :) But that's your choice. Good day to you.

– Esperento57
Nov 24 '16 at 6:37












1 Answer
1






active

oldest

votes


















3














It's not necessary to (enclose echo string in parentheses)



Try



(
echo string1
echo string2
)>filename


BUT your problem is that the ) is closing the (echo - the second ( has no effect as a special character - it's treated as a standard character, so you need to escape any literal ) to be echoed with a caret ^) (regardless of whether you use your method or mine).






share|improve this answer























  • Thanks! It's working now.

    – Will Fetzer
    Nov 7 '16 at 3:45











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40457216%2fwriting-and-executing-a-powershell-script-with-batch%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














It's not necessary to (enclose echo string in parentheses)



Try



(
echo string1
echo string2
)>filename


BUT your problem is that the ) is closing the (echo - the second ( has no effect as a special character - it's treated as a standard character, so you need to escape any literal ) to be echoed with a caret ^) (regardless of whether you use your method or mine).






share|improve this answer























  • Thanks! It's working now.

    – Will Fetzer
    Nov 7 '16 at 3:45















3














It's not necessary to (enclose echo string in parentheses)



Try



(
echo string1
echo string2
)>filename


BUT your problem is that the ) is closing the (echo - the second ( has no effect as a special character - it's treated as a standard character, so you need to escape any literal ) to be echoed with a caret ^) (regardless of whether you use your method or mine).






share|improve this answer























  • Thanks! It's working now.

    – Will Fetzer
    Nov 7 '16 at 3:45













3












3








3







It's not necessary to (enclose echo string in parentheses)



Try



(
echo string1
echo string2
)>filename


BUT your problem is that the ) is closing the (echo - the second ( has no effect as a special character - it's treated as a standard character, so you need to escape any literal ) to be echoed with a caret ^) (regardless of whether you use your method or mine).






share|improve this answer













It's not necessary to (enclose echo string in parentheses)



Try



(
echo string1
echo string2
)>filename


BUT your problem is that the ) is closing the (echo - the second ( has no effect as a special character - it's treated as a standard character, so you need to escape any literal ) to be echoed with a caret ^) (regardless of whether you use your method or mine).







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 7 '16 at 3:17









MagooMagoo

61.6k54469




61.6k54469












  • Thanks! It's working now.

    – Will Fetzer
    Nov 7 '16 at 3:45

















  • Thanks! It's working now.

    – Will Fetzer
    Nov 7 '16 at 3:45
















Thanks! It's working now.

– Will Fetzer
Nov 7 '16 at 3:45





Thanks! It's working now.

– Will Fetzer
Nov 7 '16 at 3:45



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40457216%2fwriting-and-executing-a-powershell-script-with-batch%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해