<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[gOxiA=苏繁=SuFan Blog]]></title> 
<link>https://maytide.net/index.php</link> 
<description><![CDATA[gOxiA,苏繁,sufan,Microsoft MVP]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[gOxiA=苏繁=SuFan Blog]]></copyright>
<item>
<link>https://maytide.net/read.php/1323.htm</link>
<title><![CDATA[[PowerShell] 正确使用 Windows PowerShell 执行服务器管理器操作]]></title> 
<author>gOxiA &lt;sufan_cn@msn.com&gt;</author>
<category><![CDATA[PowerShell 和脚本]]></category>
<pubDate>Sat, 14 Nov 2009 09:07:51 +0000</pubDate> 
<guid>https://maytide.net/read.php/1323.htm</guid> 
<description>
<![CDATA[ 
	<p><a href="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/powershell_logo.jpg" target="_blank"><img style="display: inline; border: 0px" src="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/powershell_logo_thumb.jpg" border="0" alt="powershell_logo" title="powershell_logo" width="200" height="200" /></a> 正确使用 Windows PowerShell 执行服务器管理器操作</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最近在学习 Exchange 2010，其中会涉及到 Exchange 2010 的安装前准备工作，而这一内容主要包括了系统角色及功能的安装，虽然通过图形界面可以执行这些操作，但是如果使用命令行来执行自动化的批量安装岂不是更好。借此机会 <a href="http://goxia.maytide.net/" target="_blank">gOxiA</a> 可以好好学习学习 Windows Server 2008 R2 的管理命令。</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 大家应该知道，在 Windows Server 2008 R2 上，Windows PowerShell 的角色更加重要了，当我们再使用 ServerManagerCmd 来执行角色和功能安装时会看到一段系统提示，告知我们这一服务器管理命令将在下一个系统版本中被抛弃，取而代之的是 Windows PowerShell cmdlet，不可否认从目前相关的介绍来看 Windows PowerShell 是非常强大的，并且已经有很多微软产品开始支持基于 Windows PowerShell 的管理。看来大势已定，不想落后就必须学习和了解 Windows PowerShell！</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其实，gOxiA 对 Windows PowerShell 了解甚少，看到那些涉及到编程语言的字符我就害怕（编程菜鸟，完全不懂的级别），这不今天就出了丑！从相关帮助中了解到，在 Windows PowerShell 下可以使用 <span style="background-color: #ffff00">Get-WindowsFeature</span>、<span style="background-color: #ffff00">Add-WindowsFeature</span> 和 <span style="background-color: #ffff00">Remove-WindowsFeature</span> 来管理服务器的角色和功能，出于之前对 Windows PowerShell 的简单认识，于是找到了附件中的 Windows PowerShell 程序并启动了它。</p><p><a href="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/WindowsPowerShell.png" target="_blank"><img style="display: inline; border: 0px" src="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/WindowsPowerShell_thumb.png" border="0" alt="WindowsPowerShell" title="WindowsPowerShell" width="411" height="460" /></a> </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在打开的 Windows PowerShell 环境下，键入了 Get-WindowsFeature，问题出来了！给我反馈了一大堆的红色错误信息，很明显 Windows PowerShell 并未识别这个命令。如下图所示：</p><p><a href="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/ps_module_error.png" target="_blank"><img style="display: inline; border: 0px" src="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/ps_module_error_thumb.png" border="0" alt="ps_module_error" title="ps_module_error" width="644" height="122" /></a>&nbsp;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 查阅了 TechNet 资源库才了解到，如果通过 Windows PowerShell 来执行服务器管理器的操作，必须加载其对应的模块 &mdash; ServerManager，我们可以在 Windows PowerShell 环境下执行&ldquo;<span style="background-color: #ffff00">Get-Module</span>&rdquo;获取当前系统中的模块。gOxiA 的个人理解是 Windows PowerShell 是一个功能强大的环境，除了内置的命令和支持以外，我们还可以通过其他产品本身提供的 Windows PowerShell 模块，为其提供在 Windows PowerShell 环境下对该产品的管理支持。比如 Exchange Server，就在其程序组中提供了一个 PoweShell 的快捷方式，通过该程序打开的 PowerShell 环境将可以直接支持 Exchange Server。</p><p><a href="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/getmodule.png" target="_blank"><img style="display: inline; border: 0px" src="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/getmodule_thumb.png" border="0" alt="get-module" title="get-module" width="644" height="157" /></a> </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 既然如此，那么在 Windows Server 2008 R2 中应该同样也提供了一个与之类似的快捷方式，原来在&ldquo;管理工具&rdquo;程序组中确实提供了一个 PowerShell 快捷方式，名为：&ldquo;Windows PowerShell Modules&rdquo;。直接启动这个程序，便可以在 Windows PowerShell 环境下执行服务器管理器操作。</p><p><a href="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/WindowsPowerShellModules.png" target="_blank"><img style="display: inline; border: 0px" src="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/WindowsPowerShellModules_thumb.png" border="0" alt="WindowsPowerShellModules" title="WindowsPowerShellModules" width="333" height="484" /></a> </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 前面已经讲过，只要 Windows PowerShell 加载对应的模块，即可以通过 Windows PowerShell 执行相关的操作。那么我们在默认 Windows PowerShell 环境下只需要执行&ldquo;<span style="background-color: #ffff00">Import-Module ModuleName</span>&rdquo;即可加载相关的模块。如下图所示：</p><p><a href="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/importmodule_servermanager.png" target="_blank"><img style="display: inline; border: 0px" src="http://goxia.maytide.net/ftpupfiles/PowerShellWindowsPowerShell_F0CF/importmodule_servermanager_thumb.png" border="0" alt="import-module_servermanager" title="import-module_servermanager" width="644" height="483" /></a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最后，需要注意的是当重新进入 Windows PowerShell 后需要重新加载需要使用的模块。关于 PowerShell 的使用 gOxiA 也在逐步进行学习和了解，希望日后能有更大的收获！ </p><br/>Tags - <a href="https://maytide.net/go.php/tags/microsoft/" rel="tag">microsoft</a> , <a href="https://maytide.net/go.php/tags/windows/" rel="tag">windows</a> , <a href="https://maytide.net/go.php/tags/powershell/" rel="tag">powershell</a> , <a href="https://maytide.net/go.php/tags/servermanager/" rel="tag">servermanager</a>
]]>
</description>
</item>
</channel>
</rss>