5

我想制作一个 bat 文件以在 Windows Server 2012 上安装 .net Framework 3.5。我尝试过这样但没有成功:

cd /D %userprofile% 
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 
Import-Module ServerManager 
powershell -ImportSystemModules Add-WindowsFeature NET-Framework-Features

似乎进入powershell控制台后最后2个命令没有执行。

有谁知道为什么会卡住?

或者是否有人有其他 bat 文件如何在 Windows Server 2012 中自动安装 .net 3.5?

经过更多尝试后,我让蝙蝠在手动运行时使用以下命令。

call C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ImportSystemModules Add-WindowsFeature NET-Framework-Features

但是当我尝试从 dotnetInstaller 运行它时,相同的 bat 不再工作

 <component command="CMD.EXE /K &quot;#APPPATH\Install.net3.5.bat&quot;" command_silent="" command_basic="" uninstall_command="" uninstall_command_silent="" uninstall_command_basic="" returncodes_success="" returncodes_reboot="" disable_wow64_fs_redirection="False" id=".Net 3.5 SP1 Win8Server" display_name=".Net 3.5 SP1" uninstall_display_name="" os_filter="" os_filter_min="winServer2008R2" os_filter_max="" os_filter_lcid="" type="cmd" installcompletemessage="" uninstallcompletemessage="" mustreboot="False" reboot_required="" must_reboot_required="False" failed_exec_command_continue="" allow_continue_on_error="True" default_continue_on_error="False" required_install="True" required_uninstall="True" selected_install="True" selected_uninstall="True" note="" processor_architecture_filter="" status_installed="" status_notinstalled="" supports_install="True" supports_uninstall="False" show_progress_dialog="True" show_cab_dialog="True">
 <installedcheck path="SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" fieldname="Install" fieldvalue="1" defaultvalue="False" fieldtype="REG_DWORD" comparison="match" rootkey="HKEY_LOCAL_MACHINE" wowoption="NONE" type="check_registry_value" description="Installed Check" />
      <installedcheck path="SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" fieldname="SP" fieldvalue="1" defaultvalue="False" fieldtype="REG_DWORD" comparison="match" rootkey="HKEY_LOCAL_MACHINE" wowoption="NONE" type="check_registry_value" description="Installed Check" />
    </component>  

我收到此错误知道为什么吗?

术语“Add-WindowsFeature”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含 ap ath,请验证路径是否正确,然后重试。在 line:1 char:19 + Add-WindowsFeature <<<< -name net-framework-features + CategoryInfo : ObjectNotFound: (Add-WindowsFeature:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

4

6 回答 6

4

两种选择:

1) 使用脚本文件和 File 参数。

#############
## script.ps1
Import-Module ServerManager
Add-WindowsFeature NET-Framework-Features

然后执行:

powershell -File c:\script.ps1

2)使用命令参数:

powershell -Command "Import-Module ServerManager; Add-WindowsFeature NET-Framework-Features"

在任何情况下,尽量避免使用 -ImportSystemModules 开关(在 v3 中已弃用),这只是矫枉过正。当您只需要 ServerManager 模块时,它将加载所有系统模块。如果您使用的是 v3,则 Import-Module 命令也是多余的。请参阅模块自动加载功能

于 2013-04-05T12:59:46.503 回答
1

我使它与这个蝙蝠一起工作:

call C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ImportSystemModules Add-WindowsFeature NET-Framework-Features

在 dotnetInstaller 引导程序中:

<component command="Install.net3.5.bat" command_silent="" command_basic="" uninstall_command="" uninstall_command_silent="" uninstall_command_basic="" returncodes_success="" returncodes_reboot="" disable_wow64_fs_redirection="True" id=".Net 3.5 SP1 Win8Server" display_name=".Net 3.5 SP1" uninstall_display_name="" os_filter="" os_filter_min="winServer2008R2" os_filter_max="" os_filter_lcid="" type="cmd" installcompletemessage="" uninstallcompletemessage="" mustreboot="False" reboot_required="" must_reboot_required="False" failed_exec_command_continue="" allow_continue_on_error="True" default_continue_on_error="False" required_install="True" required_uninstall="True" selected_install="True" selected_uninstall="True" note="" processor_architecture_filter="" status_installed="" status_notinstalled="" supports_install="True" supports_uninstall="False" show_progress_dialog="True" show_cab_dialog="True">
 <installedcheck path="SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" fieldname="Install" fieldvalue="1" defaultvalue="False" fieldtype="REG_DWORD" comparison="match" rootkey="HKEY_LOCAL_MACHINE" wowoption="NONE" type="check_registry_value" description="Installed Check" />
      <installedcheck path="SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" fieldname="SP" fieldvalue="1" defaultvalue="False" fieldtype="REG_DWORD" comparison="match" rootkey="HKEY_LOCAL_MACHINE" wowoption="NONE" type="check_registry_value" description="Installed Check" />
    </component>  

似乎它以前不起作用,因为引导程序将 bat 进程作为 PS 不喜欢的 32 位启动。所以我把 disable_wow64_fs_redirection="True" 现在它作为 64 位进程运行 bat 并且它可以工作:)

谢谢大家的回复。我发布了答案可能会对其他人有所帮助:)

于 2013-04-08T09:34:03.100 回答
0

这通过以下方式工作:

cd /D %userprofile% 
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "Import-Module ServerManager; ImportSystemModules Add-WindowsFeature NET-Framework-Features"
pause
于 2013-04-05T12:28:47.543 回答
0

要使用 powershell 运行命令,请使用 -Command 参数,如下所示:

powershell.exe -command "&{Import-Module ServerManager; ImportSystemModules Add-WindowsFeature NET-Framework-Features}"
于 2013-04-05T12:29:44.830 回答
0

转到命令提示符并输入以下内容:

dism /online /enable-feature /featurename:NetFX3 /all /Source:d:\sources\sxs /LimitAccess

注意:来源应为 Windows 2012 安装光盘。就我而言,它位于 D:

于 2013-08-04T22:23:53.200 回答
0

你也可以使用巧克力

choco install dotnet3.5
于 2018-10-07T05:59:25.417 回答