Using information I found here, I am still unable to get this to work.
I have created the following .bat
file, to call the PowerShell script on Windows 10 Professional.
for /f "delims=" %%a in ('powershell.exe -executionpolicy remotesigned ".\dang.ps1"') do (set "$crap=%%a")
powershell.exe .\dang.ps1
echo %$crap%
You will notice that it calls the PowerShell script two different ways.
This is the PowerShell script which is being launched from the batch file.
$crap="Pain in my butt"
return $crap
The strange thing is about this. When the batch file tries to launch the PowerShell script from the for /f
loop, I receive the following error message:
C:\Users\pgmrd\My Drive\DLSR Notes and backup\Software\Scripts>(set "$crap=program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again." )
C:\Users\pgmrd\My Drive\DLSR Notes and backup\Software\Scripts>(set "$crap=At line:1 char:1" )
C:\Users\pgmrd\My Drive\DLSR Notes and backup\Software\Scripts>(set "$crap=+ .\dang.ps1
:\Users\pgmrd\My Drive\DLSR Notes and backup\Software\Scripts>(set "$crap=+ ~~~~~~~~~~~" )
C:\Users\pgmrd\My Drive\DLSR Notes and backup\Software\Scripts>(set "$crap= + CategoryInfo : ObjectNotFound: (.\dang.ps1String) [], CommandNotFoundException" )
C:\Users\pgmrd\My Drive\DLSR Notes and backup\Software\Scripts>(set "$crap= + FullyQualifiedErrorId : CommandNotFoundException" )
C:\Users\pgmrd\My Drive\DLSR Notes and backup\Software\Scripts>(set "$crap= " )
BUT, when I launch the same PowerShell script, (see last line of batch file), without using the for /f
, it has no problem executing the script.
C:\Users\pgmrd\My Drive\DLSR Notes and backup\Software\Scripts>powershell.exe .\dang.ps1
Pain in my butt
The scripts I typed are very stripped down so that I could concentrate on making it work. BUT, the final batch file runs some backups. Will launch the PowerShell script to read a xml file and return a file path. Then use that file path in the rest of the backup batch file.