Install powershell via batch file

rwskas
rwskas used Ask the Experts™
on
I need help with a batch file to install powershell.
What I would like to do is have a batch file that can check to see if you already have powershell v1.0 installed, and check to see if you have .NET Framework 2.0 installed, and install the ones they dont have from a shared location. I know how to install MSIs from bat files, but I am unsure how to go about writing the piece that checks if its already installed.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
TechnoChatWintel Administrator / Cloud Computing

Commented:
OK,
I have created attached script which will check the status of .net 2.0 is installed or not, if it installed, only power shell will be installed, if not then it will start install .Net 2.0 then PowerShell.

Note: I am not 100% sure about silent install switch for both, you have to modify the switch if required.

Thanks
Sauagta
@echo off
dir /b %windir%\Microsoft.NET\Framework | findstr v2.0 >%tmp%\nchk.txt
dir %tmp%\nchk* | findstr File >%tmp%\nchksize.txt
FOR /F "tokens=3" %%a in (%tmp%\nchksize.txt) do set fsize=%%a
if %fsize% == 0 goto _installnet2
::start /wait \\UNCpath\WindowsXP-KB926139-v2-x86-ENU.exe /quiet /passive /norestart
exit
:_installnet2
start /wait \\UNCpath\.Net_2.0_Setup.exe /q:a /c:"install /l /q"
start /wait \\UNCpath\WindowsXP-KB926139-v2-x86-ENU.exe /quiet /passive /norestart
exit

Open in new window

Author

Commented:
I also need it to check and see if powershell itself is installed, as this is going to be added into a install script that does a handful of other things after its verified that powershell is installed.
TechnoChatWintel Administrator / Cloud Computing

Commented:
Done.. :)
Try attached.

Thanks
Saugata
@echo off
if not exist "C:\WINDOWS\system32\WindowsPowerShell" goto main
exit
:main
dir /b %windir%\Microsoft.NET\Framework | findstr v2.0 >%tmp%\nchk.txt
dir %tmp%\nchk* | findstr File >%tmp%\nchksize.txt
FOR /F "tokens=3" %%a in (%tmp%\nchksize.txt) do set fsize=%%a
if %fsize% == 0 goto _installnet2
::start /wait \\UNCpath\WindowsXP-KB926139-v2-x86-ENU.exe /quiet /passive /norestart
exit
:_installnet2
start /wait \\UNCpath\.Net_2.0_Setup.exe /q:a /c:"install /l /q"
start /wait \\UNCpath\WindowsXP-KB926139-v2-x86-ENU.exe /quiet /passive /norestart
exit

Open in new window

Wintel Administrator / Cloud Computing
Commented:
One small mistake..!!

Try this..

Thanks
Saugata

@echo off
if not exist "%windir%\system32\WindowsPowerShell" goto main
exit
:main
dir /b %windir%\Microsoft.NET\Framework | findstr v2.0 >%tmp%\nchk.txt
dir %tmp%\nchk* | findstr File >%tmp%\nchksize.txt
FOR /F "tokens=3" %%a in (%tmp%\nchksize.txt) do set fsize=%%a
if %fsize% == 0 goto _installnet2
::start /wait \\UNCpath\WindowsXP-KB926139-v2-x86-ENU.exe /quiet /passive /norestart
exit
:_installnet2
start /wait \\UNCpath\.Net_2.0_Setup.exe /q:a /c:"install /l /q"
start /wait \\UNCpath\WindowsXP-KB926139-v2-x86-ENU.exe /quiet /passive /norestart
exit

Open in new window

Author

Commented:
Was close enough to get me going, thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial