0

Using a series of scripts to build a signage PC that opens Chrome and displays a specific URL. I have been manually setting the URL withing the powershell script that opens Chrome and displays the page. Since a batch is used to do some setting up of the unit, I'd like to set the $URL variable in the PS1 via a prompt during the setup bat.

I have tried a few things from other threads with no luck. I have little experience with batch or powershell. Not a task I was given but figured it may be nice to improve what I have been given as the current standard procedure.

Thanks in advance.

1

1 Answer 1

1

In my experience, the best way to transfer info from Batch to PowerShell is to use environment variables.

For example, if you have a PowerShell script named MyPowerShellScript.ps1, having the following content:

$URL = $Env:URL
Write-Host "[URL=$URL]"

And call it with the following batch file:

@ECHO OFF
REM As per mklement0's comment, SETLOCAL limits environment changes to batch file
SETLOCAL
SET "URL=https://stackoverflow.com/"
PowerShell -NoProfile -ExecutionPolicy Bypass -file MyPowerShellScript.ps1

Will give this output:

[URL=https://stackoverflow.com/]
Sign up to request clarification or add additional context in comments.

1 Comment

setlocal is need for .cmd files too (just tried it), so I don't think the extension matters here. You definitely want this to be an explicit feature, otherwise you wouldn't be able to set process-level environment variables.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.