Member_2_6474242
asked on
how to put a powershell script inside a batch file
Hi All
I am trying to include the following into a batch file that i have that maps some drives
i have added the below to my smb.ps1
Enable-WindowsOptionalFeat ure -Online -FeatureName smb1protocol
In my batch file
powershell.exe -ExecutionPolicy Bypass -File "D:\scripts\smb.ps1"
Also note the smb script works if i test it alone
I get the error below when i execute. i have allowed allow local and remote signed scripts on dc and this is happening via GPO
"The argument 'D:\scripts\smb.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter."
I am trying to include the following into a batch file that i have that maps some drives
i have added the below to my smb.ps1
Enable-WindowsOptionalFeat
In my batch file
powershell.exe -ExecutionPolicy Bypass -File "D:\scripts\smb.ps1"
Also note the smb script works if i test it alone
I get the error below when i execute. i have allowed allow local and remote signed scripts on dc and this is happening via GPO
"The argument 'D:\scripts\smb.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter."
did you copy "D:\Scripts\smb.ps1" to every computer?
if not, this is exactly the error I would expect.
if not, this is exactly the error I would expect.
@@ECHO off
@@setlocal EnableDelayedExpansion
@@set LF=^
@@SET command=#
@@FOR /F "tokens=*" %%i in ('findstr -bv @@ "%~f0"') DO SET command=!command!!LF!%%i
@@powershell -noprofile -noexit -command !command! & goto:eof
# *** POWERSHELL CODE STARTS HERE *** #
# put the contents of the ps1 here
#
https://blogs.technet.microsoft.com/pstips/2018/01/25/embed-powershell-code-in-a-batch-file/
ASKER
Hi David
I tried the code and i got the error attachedsmb.txt
I tried the code and i got the error attachedsmb.txt
ASKER
Hi Michael
did you copy "D:\Scripts\smb.ps1" to every computer? No
Where exactly do i need to copy this to?
did you copy "D:\Scripts\smb.ps1" to every computer? No
Where exactly do i need to copy this to?
you need to run the batch file as an administrator
ASKER
ASKER
Hi David
How can i accomplish that if i put it on logon script for a user in AD
How can i accomplish that if i put it on logon script for a user in AD
don't put it in a user logon script but a computer logon script where it will run as system.
ASKER
HI David just tried that. the group policy is updated but the feature is not installed
ASKER
thanks David it seemed like it worked. I didnt have the computer name in the same ou that i was applying it to
you have to shutdown and restart one more time
ASKER
ok it didnt seem to install it
Mapping drives from the batch file, then running powershell from within it seems convoluted. Why not just put the entire thing in Powershell? You can map drives Via GPO too.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""D:\scripts\smb.ps1""' -Verb RunAs}"
And run as administrator