pandaworld78
Goto Top

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:


<# : 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.

Content-Key: 563115

Url: https://administrator.de/contentid/563115

Printed on: May 11, 2024 at 06:05 o'clock

Member: aqui
aqui Apr 04, 2020 updated at 07:55:55 (UTC)
Goto Top
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 !
Mitglied: 143728
143728 Apr 04, 2020 updated at 08:26:27 (UTC)
Goto Top
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
# ==============================================================================================================
Member: pandaworld78
pandaworld78 Apr 04, 2020 at 08:47:54 (UTC)
Goto Top
Na klar, Perfekt ! - Vielen Dank.

Manchmal sieht man den Wald vor lauter Bäumen nicht.