Link to home
Start Free TrialLog in
Avatar of rwskas
rwskasFlag for United States of America

asked on

Install powershell via batch file

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.
Avatar of TechnoChat
TechnoChat
Flag of India image

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

Avatar of rwskas

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of TechnoChat
TechnoChat
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rwskas

ASKER

Was close enough to get me going, thanks!