深入浅出PowerShell——入门

搭建环境:

Win7和Win2008中自带有PowerShell 2.0,在命令中输入powershell即可。

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=20430

使用Windows PowerShell ISE编写代码,用户体验跟写c#代码很像。在运行命令中输入powershell_ise,即可。

第三方开发工具:PowerGUI.3.1.0.2058.msi,提供智能感知功能。

常用快捷键:

 保存ps文件后可以按F9启动调试

F10跳跃调试

F11单步调试

get-command *uninstall   常看包含部分匹配的关键字的命令

get-help uninstall-spsolution -example 查看命令的使用实例

ctrl+c  换行

编程技巧

使用用PowerShell 方法库文件中的方法:

说明:GetNoByName是GetName.ps1中的一个方法。

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
. ("D:\Mingle\PS\GetName.ps1")
GetNoByName "fdsfdsafd"

使用Bat文件执行PS文件

说明:%~dp0表示当前路径

PowerShell -command Set-ExecutionPolicy "Bypass"
PowerShell -command "& {%~dp0mainbody.ps1 -path %~dp0 -configurationFilePath %~dp0\DeployemntConfiguration.xml -sectionid AZ_EIP -modulename 'Common'}"
Pause

使用write-host‘来实现辅助调试

write-host "Add Groups operation canceled"

在PowerShell中使用Exception

http://huddledmasses.org/trap-exception-in-powershell/

使用Powershell集成SharePoint的命令窗口

Tab键 关键字的自动提示

使用SharePoint对象模型

原文地址:https://www.cnblogs.com/mingle/p/2308216.html