question

winprofessional avatar image
0 Votes"
winprofessional asked ·

Calling powershellscript from batch file

I am trying to call a powershell script that contains a function that returns boolean, from a windows batch file. But I am not able to get the return value from the power shell script in the batch file. I found a couple of posts but couldn't get an answer . Below is the outline of code.

Below is the Powershell script that has a function only(Script1.ps1)

 Function Get-Value
 {
    
  $isOK = $false
  ...
   return $isOK
 }

Below is the batch file that calls the above function

 @echo off
 set val=powershell -ExecutionPolicy ByPass -File .\Script1.ps1
 @echo %val%
 pause

How can I receive the Boolean value in the batch file and use. it. I am not mush proficient in batch file/ps scripting

not-supported
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered ·

QnA currently supports the products listed in right-hand pane (more to be added) Better to reach out to subject matter experts in dedicated forums over here.


https://social.technet.microsoft.com/Forums/windows/en-US/home?forum=winserverpowershell

https://social.technet.microsoft.com/Forums/scriptcenter/en-us/home?forum=ITCG


(please don't forget to mark helpful replies as answer)




· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichardMueller-8175 avatar image
0 Votes"
RichardMueller-8175 answered ·

For one thing, you never invoke the function in your PowerShell script. Add the statement "Get-Value" at the end.
I use code similar to below in a bat file to run a PowerShell script:

@echo off
PowerShell -Command "& {.\Script1.ps1}"

Finally, you should ask your question in the PowerShell forum.

https://social.technet.microsoft.com/Forums/en-US/home?forum=winserverpowershell


· 1 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

All I want to do is delete Power Shell


0 Votes 0 · ·