Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 36188

PowerShell 4.0 deployment

$
0
0

Every once in a while I’m asked how to deploy PowerShell in the enterprise, and my answer is always: “It depends”. - It depends on the target machine’s operating system, the PowerShell version you want to install, and if you already have a deployment mechanism (such as SCCM).

For this specific scenario, there was no deployment mechanism, the OSs were Windows 7 and Windows 2008 R2, the PowerShell version needed to be installed was v4.0 and the machines didn’t have internet connectivity (This is important for the .NET Framework 4.5 installation, which is a prerequisite for PowerShell 4.0. See http://blogs.msdn.com/b/powershell/archive/2013/10/29/wmf-4-0-known-issue-partial-installation-without-net-framework-4-5.aspx).

So to make the deployment easier, I ended up writing a batch file so it could be used through GPO, SCCM, just double-click, and what not.

 

The installation script requires all the setup files to be in the same folder:

DeployWMF4

 

The full offline installer for the .NET Framework 4.5 can be downloaded from here: http://go.microsoft.com/fwlink/?LinkId=225702

The Windows Management Framework 4.0 installation packages can be downloaded from here:  http://www.microsoft.com/en-us/download/details.aspx?id=40855

(Make sure you download both packages (x86 and x64). The installation script determines the processor architecture and installs the correct package).

 

The setup script will create a log file (in the C:\Temp folder, named with the same name you use for the batch file) containing the installation process details, and a verbose log file (C:\Temp\netfx45.htm) for the .NET Framework installation.

 

Disclaimer: As are all code examples I post in this blog, the deployment batch file is provided as-is, without warranty of any kind.

DeployWMF.cmd:

@echooff
title %~nx0clsset"outputFolder=C:\Temp"if/i notexist"%outputFolder%"md"%outputFolder%">>"%outputFolder%\%~n0.log"2>&1(call:START)& endlocal& goto:eof:STARTecho %date% %time% - %~nx0 startedset RESTART=0if/i "%PROCESSOR_ARCHITECTURE%"=="x86"(ifnot defined PROCESSOR_ARCHITEW6432 (set BITNESS=x86)else(set BITNESS=x64))else(set BITNESS=x64):NETFX45
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.5"2>NULif %ERRORLEVEL% equ 0(echo.NET Framework 4.5 is already installedgoto WMF4)echo Installing .NET Framework 4.5start/wait %~dp0dotnetfx45_full_x86_x64.exe /q /log %outputFolder%\netfx45.htm /norestartif %ERRORLEVEL% equ 0goto WMF4if %ERRORLEVEL% equ 1641goto WMF4if %ERRORLEVEL% equ 3010(goto WMF4)else(echo There was an error [%ERRORLEVEL%] during the .NET Framework 4.5 installationecho Check the logs for more detailsecho Windows Management Framework 4.0 installation aborted!gotoEXIT):WMF4
reg query "HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine"/v PowerShellVersion 2>&1 | find"4.0"2>&1>NULif %ERRORLEVEL% equ 0(echo Windows Management Framework 4.0 is already installedgotoEXIT)echo Installing Windows Management Framework 4.0(%BITNESS%)start/wait wusa.exe %~dp0Windows6.1-KB2819745-%BITNESS%-MultiPkg.msu /quiet /norestartif %ERRORLEVEL% equ 0(echo Windows Management Framework 4.0 installed successfullyset RESTART=1gotoEXIT)if %ERRORLEVEL% equ 3010(echo Windows Management Framework 4.0 installed successfully - restart requiredset RESTART=1gotoEXIT)if %ERRORLEVEL% equ 2359302(echo Windows Management Framework 4.0 is already installed)else(echo There was an error [%ERRORLEVEL%] during the Windows Management Framework 4.0 installationecho Check the logs for more details):EXITecho.& echo %date% %time% - %~nx0 ended & echo.if %RESTART% equ 1 shutdown.exe -r -f -t 0

 

Though it should go without saying, please test the setup process before you use it against all (or many) computers in your environment.

Also note that not all server applications are compatible with PowerShell 4.0.  From the system requirements notes on the WMF 4.0 download page:

Systems that are running the following server applications should not run Windows Management Framework 4.0 at this time.

  • System Center 2012 Configuration Manager (not including SP1)
  • System Center Virtual Machine Manager 2008 R2 (including SP1)
  • Microsoft Exchange Server 2007
  • Windows Small Business Server 2011 Standard
Servers that are running the following applications can now run WMF 4.0. The versions listed are the minimum releases required to run WMF 4.0.

 

For some of them, you might need to change the management shell shortcut adding “-version 2”. – See KB2796733 for more details.

 

 

HTH,

\Martin.


Viewing all articles
Browse latest Browse all 36188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>