我正在尝试使用 Powershell 3.0 或 4.0 更新 Active Directory 中某个 OU 中的所有 Windows 7 计算机。我想使用组策略或 SCCM 2012,并希望将其推送,而不是让用户下载和安装。我发现的一个问题是 .Net 要求。有没有办法打包安装程序,以便它安装所需的 .Net 框架(如果尚未安装)?
答案1
您可以在 SCCM 2012 中使用应用程序而不是包。
在您的实例中,首先创建 .NET Framework 应用程序,然后创建 Powershell 应用程序。创建 PowerShell 应用程序时,设置您创建的应用程序的依赖项,名为 .NET Framework,并选中自动安装。
部署 PowerShell 应用程序时,它会检查工作站是否安装了 .NET Framework。如果已安装,它将继续安装 PowerShell;如果没有安装,它将首先安装 .NET Framework。
注意:确保为 .NET 应用程序(和 PowerShell)设置了检测方法,以便它知道如何检查是否已安装。
我将其用于.NET 4:
设置类型:注册表配置单元:HKLM 项:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full 值:整数“此注册表设置必须存在于目标系统上才能表明此应用程序的存在”已选中。
至于推送到客户端,请确保部署方法设置为必需,而不是可用。
答案2
我没有使用其中任何一个来安装 PowerShell 4,但想出了一个脚本来执行此操作。您可以了解这个想法并使用适合您环境的零碎内容。
REM Script to upgrade to .net 4.5 & Windows Management Framework 4 (incl. Powershell 4) on Win7 SP1
SETLOCAL ENABLEEXTENSIONS
SET SOURCE=Install_PowerShell4
SET DESTINATION=\\myserver\logs\Inventory\OnDemand\WMF4
SET exeDOTNET45="\\myserver\Packages\Microsoft Dot Net\4.5\dotnetfx45_full_x86_x64.exe" /quiet /norestart
SET exeWMFx64=\\myserver\Packages\WMF4\Windows6.1-KB2819745-x64-MultiPkg.msu /quiet /norestart
SET exeWMFx32=\\myserver\Packages\WMF4\Windows6.1-KB2819745-x86-MultiPkg.msu /quiet /norestart
REM Set Exclusions
REG QUERY HKLM\SOFTWARE\EUDE /V DoNotUpgradeToDotNet45
IF %ERRORLEVEL% EQU 0 GOTO :TAG_EXCEPTION_NET45
REG QUERY HKLM\SOFTWARE\EUDE /V DoNotUpgradeToPowerShell4
IF %ERRORLEVEL% EQU 0 GOTO :TAG_EXCEPTION_PS4
:CONTINUE
:CHECK_FailED
REM If failed before, do not retry.
IF EXIST "%DESTINATION%\Fail_DotNet_%COMPUTERNAME%.txt" GOTO :END
IF EXIST "%DESTINATION%\%COMPUTERNAME%_Has_PowerShell4.txt" GOTO :END
IF EXIST "%DESTINATION%\Success_PowerShell4_%COMPUTERNAME%.txt" GOTO :END
:Check_For_DotNet4.5
REG QUERY "hklm\software\microsoft\net framework setup\ndp\v4\Full" /v Release
If %ERRORLEVEL% EQU 0 GOTO :Has_DotNet45
REM Does not have .net 4.5, need remediation
:Install_DotNet4.5
REM http://msdn.microsoft.com/en-us/library/ee390831.aspx for return codes
cmd /c %exeDOTNET45%
If %ERRORLEVEL% EQU 0 GOTO :DOTNET45_SUCCESS
If %ERRORLEVEL% EQU 1640 GOTO :DOTNET45_SUCCESS
If %ERRORLEVEL% EQU 3010 GOTO :DOTNET45_SUCCESS
REM GOTO :DOTNET45_Fail
:DOTNET45_Fail
IF NOT EXIST "%DESTINATION%\Fail_DotNet45_%COMPUTERNAME%.txt" ECHO. >"%DESTINATION%\Fail_DotNet45_%COMPUTERNAME%.txt"
GOTO :END
:DOTNET45_SUCCESS
IF NOT EXIST "%DESTINATION%\Success_DotNet45_%COMPUTERNAME%.txt" ECHO. >"%DESTINATION%\Success_DotNet45_%COMPUTERNAME%.txt"
GOTO :Check_For_PowerShell4
:Has_DotNet45
REM IF NOT EXIST "%DESTINATION%\%COMPUTERNAME%_HasDotNet45.txt" ECHO. >"%DESTINATION%\%COMPUTERNAME%_HasDotNet45.txt"
REM GOTO :Check_For_PowerShell4
:Check_For_PowerShell4
REG QUERY hklm\software\microsoft\powershell\3\PowerShellEngine /v PowerShellVersion |findstr "4"
IF %ERRORLEVEL% EQU 0 GOTO :Has_PowerShell4
REM Check if we have installed it but waiting for reboot
IF EXIST "%DESTINATION%\SuccessPendingReboot_PowerShell4_%COMPUTERNAME%.txt" GOTO :END
:Check_Architecture
if /i "%processor_architecture%"=="x86" (
IF NOT DEFINED PROCESSOR_ARCHITEW6432 (
cmd /c %windir%\System32\wusa.exe %exeWMFx32%
) ELSE (
cmd /c %windir%\System32\wusa.exe %exeWMFx64%
)
) else (
cmd /c %windir%\System32\wusa.exe %exeWMFx64%
)
If %ERRORLEVEL% EQU 0 GOTO :PowerShell4_SUCCESS
If %ERRORLEVEL% EQU 1640 GOTO :PowerShell4_SUCCESS
If %ERRORLEVEL% EQU 3010 GOTO :PowerShell4_SUCCESS
REM GOTO :PowerShell4_Fail
:PowerShell4_Fail
IF NOT EXIST "%DESTINATION%\Fail_PowerShell4_%COMPUTERNAME%.txt" ECHO %ERRORLEVEL% >"%DESTINATION%\Fail_PowerShell4_%COMPUTERNAME%.txt"
GOTO :END
:PowerShell4_SUCCESS
IF NOT EXIST "%DESTINATION%\SuccessPendingReboot_PowerShell4_%COMPUTERNAME%.txt" ECHO. >"%DESTINATION%\SuccessPendingReboot_PowerShell4_%COMPUTERNAME%.txt"
IF EXIST "%DESTINATION%\Fail_PowerShell4_%COMPUTERNAME%.txt" del /f /q "%DESTINATION%\Fail_PowerShell4_%COMPUTERNAME%.txt"
GOTO :END
:Has_PowerShell4
REM IF EXIST "%DESTINATION%\SuccessPendingReboot_PowerShell4_%COMPUTERNAME%.txt" (
IF EXIST "%DESTINATION%\Fail_PowerShell4_%COMPUTERNAME%.txt" del /f /q "%DESTINATION%\Fail_PowerShell4_%COMPUTERNAME%.txt"
IF EXIST "%DESTINATION%\WindowsUpdateStopped_%COMPUTERNAME%.txt" del /f /q "%DESTINATION%\WindowsUpdateStopped_%COMPUTERNAME%.txt"
del /f /q "%DESTINATION%\SuccessPendingReboot_PowerShell4_%COMPUTERNAME%.txt"
ECHO. >"%DESTINATION%\Success_PowerShell4_%COMPUTERNAME%.txt"
REM ) ELSE (
REM ECHO. >"%DESTINATION%\%COMPUTERNAME%_Has_PowerShell4.txt"
REM )
GOTO :END
:TAG_EXCEPTION_NET45
IF NOT EXIST "%DESTINATION%\DoNotUpgradeToDotNet45_%COMPUTERNAME%.txt" (
eventcreate /L "APPLICATION" /T Information /SO "%SOURCE%" /id 779 /d "Tagged with DoNotUpgradeToDotNet45"
ECHO. >"%DESTINATION%\DoNotUpgradeToDotNet45_%COMPUTERNAME%.txt"
)
GOTO :END
:TAG_EXCEPTION_PS4
IF NOT EXIST "%DESTINATION%\DoNotUpgradeToPowerShell4_%COMPUTERNAME%.txt" (
eventcreate /L "APPLICATION" /T Information /SO "%SOURCE%" /id 779 /d "Tagged with DoNotUpgradeToPowerShell4"
ECHO. >"%DESTINATION%\DoNotUpgradeToPowerShell4_%COMPUTERNAME%.txt"
)
GOTO :END
:WindowsUpdateStopped
IF NOT EXIST "%DESTINATION%\WindowsUpdateStopped_%COMPUTERNAME%.txt" (
ECHO. >"%DESTINATION%\WindowsUpdateStopped_%COMPUTERNAME%.txt"
)
GOTO :END
:END
ENDLOCAL
Exit /b