Scandinavian PowerShell User Group

Script to check for installed PowerShell and to change ExecutionPolicy

rated by 0 users
This post has 0 Replies | 1 Follower

Top 10 Contributor
Male
Posts 44
Points 1,455
Fredrik Wall Posted: 11-12-2008 11:54

Script to check for installed PowerShell and to change ExecutionPolicy.
For Windows 2008

More information about this can be found in my blogpost,
http://powershellug.com/blogs/thewall/archive/2008/11/12/windows-2008-and-hyper-v-machines-part-2.aspx 

My cmd file:
depllab.cmd
-----------------------------------

@echo off
cls
Echo Lab Deploy script
Echo by Fredrik Wall, fredrik.wall@truesec.se
Echo.

setlocal

for /f "tokens=*" %%i in ('ver.exe') do set windowsversion=%%i

if "%windowsversion%" == "Microsoft Windows [Version 6.0.6001]" goto PowerShellchkwin2008

:PowerShellchkwin2008
Echo Windows 2008 detected on this machine
Echo Checking for PowerShell and install it if needed
if not exist "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" servermanagercmd.exe -install PowerShell
goto setreg


:setreg
Echo Checking current status of the Execution Policy for PowerShell
for /f "tokens=*" %%i in ('PowerShell.exe Get-ExecutionPolicy') do set exmode=%%i
if not "%exmode%" == "Unrestricted" Echo ExecutionPolicy will be changed to Unrestricted now
if not "%exmode%" == "Unrestricted" PowerShell.exe Set-ExecutionPolicy Unrestricted
if "%exmode%" == "Unrestricted" Echo ExecutionPolicy are set to Unrestricted
goto runscript

:runscript
PowerShell.exe ".\deplab.ps1"

:end

Page 1 of 1 (1 items) | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems