![](/img/trans.png)
[英]PowerShell DSC, Server 2019, .NET 3.5 failing to install from source
[英]bat file to install .net 3.5 framework for win server 2012
我想制作一個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運行它同樣的蝙蝠不再工作
<component command="CMD.EXE /K "#APPPATH\Install.net3.5.bat"" 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,functi on,腳本文件或可操作程序的名稱。 檢查名稱的拼寫,或者如果包含ap 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功能 。
我用它擊球了:
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>
似乎它之前沒有用,因為引導程序以32位開始蝙蝠進程而PS不喜歡。 所以我把disable_wow64_fs_redirection =“True”現在它運行蝙蝠作為64位進程,它的工作原理:)
謝謝大家的回復。 我發布的答案可能會幫助別人:)
這按以下方式工作:
cd /D %userprofile%
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "Import-Module ServerManager; ImportSystemModules Add-WindowsFeature NET-Framework-Features"
pause
要使用powershell運行命令,請使用-Command參數,如下所示:
powershell.exe -command "&{Import-Module ServerManager; ImportSystemModules Add-WindowsFeature NET-Framework-Features}"
轉到命令提示符並輸入以下內容:
dism / online / enable-feature / featurename:NetFX3 / all / Source:d:\\ sources \\ sxs / LimitAccess
注意:Source應該是Windows 2012安裝光盤。 就我而言,這位於D:
你也可以使用巧克力 :
choco install dotnet3.5
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.