郁闷小甜甜 发表于 2008-12-14 11:22:34

Windows

微软windowsvistablog上,开发人员列举了Windows Vista中Windows PowerShell所提供的12项酷酷的功能:

<P>  解答PowerShell:PowerShell原来的开发代号是Monad,原计划是用以替代Windows中的命令行工具,但是后来微软说它只是技术上的扩充。使用PowerShell,管理员可以做任何在图形界面下所做的事情。Windows PowerShell 1.0可以运行在Windows XP SP2、Windows Server 2003和Windows Vista上。</P>

<P> <STRONG> 1. 内置Cmdlets (即"commandlets")</STRONG></P>

<P>  Windows PowerShell中的所有Cmdlets都允许这样的动名词:get-service, get-process, stop-service, get-wmiobject.</P>

<P> <STRONG> 2. 强大的通配符和操作对象</STRONG></P>

<P>  要得到以w开头的服务及其依赖服务只要输入: 





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; get-service w*   format-list DisplayName, DependentServices</TD></TR> <STRONG> 3. 在犯错误前测试命令</STRONG></P>

<P>  Windows PowerShell 有意向独特的功能:Whatif ,可以不执行命令就告诉你命令执行结果.如: 





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; stop-service w3* -whatif</TD></TR> <STRONG> 4. 获取副本</STRONG></P>

<P>  PowerShell 可以开始和结束所有命令的副本,可以在脚本中轻易测试命令并同时保存.  





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; Start-Transcript -Path c:demodfoshow.txt <BR>PS&gt; Stop-Transcript</TD></TR>  <STRONG>5. 从命令行发布Windows对话</STRONG></P>

<P>  因为Windows PowerShell位对象而优化,可以向.NET Framework一样从命令行访问COM对象,下列命令告诉你的Vista机器发表"Windows Vista and PowerShell"字串.  





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; $spVoice = new-object -com "SAPI.spvoice" <BR>PS&gt; $spVoice.Speak("Windows Vista and PowerShell")</TD></TR> <STRONG> 6. 使用Windows PowerShell访问诸如Windows Media Player 11等的应用程序  </STRONG>





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; $band = "The Posies" <BR>PS&gt; $player = New-object -com wmplayer.ocx <BR>PS&gt; $playlist = $player.mediacollection.getbyauthor($band) <BR>PS&gt; $player.openPlayer($playlist.item(0).sourceurl)</TD></TR><STRONG>  7. Windows PowerShell作为命令行存储计算器</STRONG></P>

<P>  PowerShell可以完成基本的计算工作  





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; 2*2</TD></TR>  不过,Windows PowerShell也可以快速解决存储问题,例如,备份11GB的数据需要多少个700MB的CD.  





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; 11gb/700mb</TD></TR>  那么,需要多少个1000GB的存储来备份每个320GB,共425个的Vista桌面呢?  





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS &gt; (320gb*425)/1000GB</TD></TR>   </P>

<P></p><p align='center'><b> 下一页 </b></p> <

                </P>

<P><STRONG>8. PowerShell 用作日历计算 </STRONG></P>

<P></P>

<P>  计算多少天到新年:  





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; ("1/1/2007" -::now).days</TD></TR>  <STRONG>9. 返回机器上某种类型文件的数量</STRONG></P>

<P>  Windows Vista有许多类型的事件记录和组策略文件等.下列命令是返回当前目录及其子目录中VBScript, Bat 和 PowerShell 脚本的数量:  





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; dir -include *.vbs, *.ps1, *.bat -recurse   group-object extension -noelement</TD></TR></P>

<P> <STRONG> 10. 从命令行收集Windows System Assessment Tool数据  </STRONG>





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; get-wmiobject win32_winsat   format-table __SERVER, *SCORE -autosize <BR>PS&gt; get-wmiobject win32_winsat   select *score   out-chart -Title "System Assessment Scores by PowerGadgets"</TD></TR><STRONG>  11. 配置UAC(User Account Control) </STRONG>





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS&gt; set-itemproperty -path HKLM:SOFTWAREMICROSOFTWINDOWSCurrentVersionPoliciesSystem -name ConsentPromptBehaviorAdmin -value 0</TD></TR>  <STRONG>12. 管理BitLocker  </STRONG>





<TR>

<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>PS &gt; $drives = get-wmiobject -namespace rootCIMv2SecurityMicrosoftVolumeEncryption -class Win32_EncryptableVolume <BR>PS&gt; $drives   format-table DriveLetter, PersistentVolumeID -autosize <BR>PS&gt; $BitLockDrive = $drives <BR>PS&gt; $BitLockDrive.GetProtectionStatus() <BR>PS&gt; $BitLockDrive.DisableKeyProtectors() <BR>PS&gt; $BitLockDrive.EnableKeyProtectors()</TD></TR></P>

</p><p align='center'><b>上一页 </b></p> <
页: [1]
查看完整版本: Windows