加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

powershell – bat文件为win server 2012安装.net 3.5框架

发布时间:2020-12-14 03:53:27 所属栏目:Windows 来源:网络整理
导读:我想制作一个bat文件来在 Windows Server 2012上安装.net Framework 3.5. 我试过这样但没有成功: cd /D %userprofile% C:WindowsSystem32WindowsPowerShellv1.0powershell.exe Import-Module ServerManager powershell -ImportSystemModules Add-Windo
我想制作一个bat文件来在 Windows Server 2012上安装.net Framework 3.5.
我试过这样但没有成功:

cd /D %userprofile% 
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe 
Import-Module ServerManager 
powershell -ImportSystemModules Add-WindowsFeature NET-Framework-Features

似乎在进入powershell控制台后,最后2个命令没有被执行.

有谁知道为什么会卡住?

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

经过多次尝试后,我在手动运行时使用以下命令.

call C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -ImportSystemModules Add-WindowsFeature NET-Framework-Features

但是,当我尝试从dotnetInstaller运行它同样的蝙蝠不再工作

<component command="CMD.EXE /K &quot;#APPPATHInstall.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="SOFTWAREMicrosoftNET Framework SetupNDPv3.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="SOFTWAREMicrosoftNET Framework SetupNDPv3.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的名称functi
on,脚本文件或可操作程序.检查名称的拼写,或者如果是p
包括ath,验证路径是否正确,然后再试一次.
在行:1 char:19
??Add-WindowsFeature<<<< -name net-framework-features
??????CategoryInfo:ObjectNotFound:(Add-WindowsFeature:String)[],
???CommandNotFoundException
??????FullyQualifiedErrorId:CommandNotFoundException

解决方法

两种选择:

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

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

然后执行:

powershell -File c:script.ps1

2)使用Command参数:

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

在任何情况下,尽量避免使用-ImportSystemModules开关(在v3中弃用),这只是一种矫枉过正.当您只需要ServerManager模块时,它将加载所有系统模块.如果您在v3中工作,Import-Module命令也是多余的.请参见模块autp-loading feature.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读