Batch with PowerShell
Hallo,
evtl. kann mir hier bei meinem Problem jemand helfen ?
Es geht darum, die Variable (Variable_1) von PowerShell innerhalb einer Batch in die eigentliche Batch zu übernehmen / übertragen.
Hier mein Code:
. . . und ja, es hat Gründe, weshalb ich die Batch dazu brauche.
evtl. kann mir hier bei meinem Problem jemand helfen ?
Es geht darum, die Variable (Variable_1) von PowerShell innerhalb einer Batch in die eigentliche Batch zu übernehmen / übertragen.
Hier mein Code:
<# : Beginn_Batch_with_PowerShell
::
@ECHO OFF
::
:: Datei: batch_with_powershell.bat
::
::==============================================================================================================
:: Shell
::==============================================================================================================
::
title Batch_with_PowerShell
setLocal EnableExtensions EnableDelayedExpansion
::
powershell -executionpolicy remotesigned -Command "Invoke-Expression $([System.IO.File]::ReadAllText('%~f0'))"
echo Shell : %Variable_1% ( Hier soll die Variable '$Variable_1' von PowerShell angezeigt werden )
echo hier_1 && pause && exit
::
#>
# ==============================================================================================================
# PowerShell
# ==============================================================================================================
#
$Variable_1 = "test"
#
Write-Host "PowerShell : " -foreground "White" -nonewline; Write-Host "$Variable_1" -foreground "DarkCyan"
# ==============================================================================================================
. . . und ja, es hat Gründe, weshalb ich die Batch dazu brauche.
Please also mark the comments that contributed to the solution of the article
Content-Key: 563115
Url: https://administrator.de/contentid/563115
Printed on: May 11, 2024 at 06:05 o'clock
3 Comments
Latest comment
Bitte dringend Code Tags benutzen !! Formatting instructions in the posts
Dann kann man auch verständlich lesen um was es geht !!
Und ja... es hat Gründe FAQs mal zu lesen ! Das hilft wirklich !
Dann kann man auch verständlich lesen um was es geht !!
Und ja... es hat Gründe FAQs mal zu lesen ! Das hilft wirklich !
Die Variable mit einer For-Schleife capturen, wie halt immer im Batch-Sandkasten ...
<# : Beginn_Batch_with_PowerShell
::
@ECHO OFF
::
:: Datei: batch_with_powershell.bat
::
::==============================================================================================================
:: Shell
::==============================================================================================================
::
title Batch_with_PowerShell
setLocal EnableExtensions EnableDelayedExpansion
::
for /f "delims=" %%a in ('powershell -executionpolicy remotesigned -Command "iex ([System.IO.File]::ReadAllText('%~f0'))"') do set "Variable_1=%%a"
echo Shell : %Variable_1%
pause && exit
::
#>
# ==============================================================================================================
# PowerShell
# ==============================================================================================================
#
$Variable_1 = "Test"
return $Variable_1
# ==============================================================================================================