SharePoint自动化系列——Site/Web/List级别的导航菜单
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/
需求:在不同的测试用例中,对脚本中不确定的因素需要和用户交互来确定,比如选择哪个site,选择哪个web,选择哪个list。当然也可以手动的copy url来传参到脚本,不过比较不友好。最好的方法是不需要复制粘贴这种,直接在不确定因素的地方做出个导航菜单来,让脚本使用者自选。
代码如下:
Add-PSSnapin Microsoft.SharePoint.PowerShell
function List($target)
{
if($target.count -gt 1)
{
for($i=1;$i -le $target.count;$i++)
{
"["+$i+"]"+$target[$i-1] | Write-Host -ForegroundColor Yellow
}
}else
{
"[1]"+$target | Write-Host -ForegroundColor Yellow
}
}
$siteUrls = Get-SPSite | select {$_.url}
Write-Host "Here are the sites:" -ForegroundColor Cyan
List($siteUrls.'$_.url')
$choice = Read-Host "Choose the site by number before"
$theSite = Get-SPSite $siteUrls[[int]$choice-1].'$_.url'
Write-Host "Here are the webs:" -ForegroundColor Cyan
$webUrls = $theSite.AllWebs.url
List($webUrls)
$choice = Read-Host "Choose the web by number before"
Write-Host "Here are the lists:" -ForegroundColor Cyan
if($webUrls.count -lt 1){
$theWeb = Get-SPWeb $webUrls[[int]$choice-1]
}else{
$theWeb = $theSite.rootweb
}
$listTitles = $theWeb.lists.title
List($listTitles)
$choice = Read-Host "Choose the list by number before"
$theList = $theWeb.lists[$listTitles[[int]$choice-1]]
$theItem = ($theList.Items)[0]
$theFile = $theWeb.GetFile($theItem.Url)
运行效果如下:

实际应用:
在实际的编写SharePoint自动化脚本的过程中,可以把这段导航安插在不确定因素(Site/Web/List)出现的地方,最后我们会把用户选择的相应Site,Web以及List分别存储在三个变量中,分别为:$theSite,$theWeb,$theList。在之后的编写脚本的过程中,可以对这三个变量进行取用。来完成对Site,Web以及List中对象的操作。
SharePoint自动化系列——Site/Web/List级别的导航菜单的更多相关文章
- Bing Maps进阶系列七:Bing Maps功能导航菜单华丽的变身
Bing Maps进阶系列七:Bing Maps功能导航菜单华丽的变身 Bing Maps Silverlight Control所提供的功能导航是非常强大的,在设计上对扩展的支持非常好,提供了许多用 ...
- SharePoint自动化系列——Add content type to list.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...
- SharePoint自动化系列——Upload files to SharePoint library using PowerShell.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的 ...
- SharePoint自动化系列——Select-option标签的定位方法总结
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ C#中通过Selenium定位页面上的select-option结构,尝试了以下几种方法,均没有生 ...
- SharePoint 2013技巧分享系列 - 隐藏Blog和Apps左侧导航菜单
企业内部网中,不需要员工创建Blog或者创建,安装SharePoint应用,因此需要在员工个人Web页面需要隐藏Blog或者Apps导航菜单, 其步骤设置如下: 该技巧适合SharePoint 201 ...
- SharePoint自动化系列——通过PowerShell创建SharePoint Web
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...
- SharePoint自动化系列——通过PowerShell创建SharePoint Site Collection
通过PowerShell创建SharePoint Site Collection,代码如下: Add-PSSnapin microsoft.sharepoint.powershell function ...
- SharePoint自动化系列——Manage "Site Subscriptions" using PowerShell
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 你可以将普通的sites加入到你的site subscriptions中,前提是你需要有一个 Te ...
- SharePoint自动化系列——Create a local user and add to SharePoint
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 实现过程:在本地创建一个local user并将该user添加到Administrators组中, ...
随机推荐
- smarty -- foreach用法
{foreach},{foreachelse} 用于像访问序数数组一样访问关联数组 {foreach},{foreachelse} {foreach} is used to loop over an ...
- MAC开发NDK非常的简单
转自:http://www.cnblogs.com/jarrah/archive/2013/03/15/2961892.html 附带CDT的下载:http://www.eclipse.org/cdt ...
- 继承 Bean 配置
继承 Bean 配置 Spring 允许继承 bean 的配置, 被继承的 bean 称为父 bean. 继承这个父 Bean 的 Bean 称为子 Bean子 Bean 从父 Bean 中继承配置, ...
- fackbook的Fresco的多种图片加载方法以及解码过程
上篇文章中我们提到了图片加载其实是用了三条线程,如果没看过的同学可以先了解下这里. fackbook的Fresco的Image Pipeline以及自身的缓存机制 那么今天我们就来探索一下如何在代码中 ...
- BackgroundWorker的使用
一个程序中需要进行大量的运算,并且需要在运算过程中支持用户一定的交互,为了获得更好的用户体验,使用BackgroundWorker来完成这一功能. 基本操作: bgw.RunWorkerAsync ...
- mac ruby rails安装(使用rvm)
mac的场合: which ruby -> /usr/bin/ruby -> 这是mac自带的ruby,我们希望能用管理ruby的版本. 安装rvm curl -L https://get ...
- Ado.net连接池 sp_reset_connection 概念
什么是连接池? 正常情况下,每次访问数据库都会打开和关闭,中断物理连接后需要再次进行物理连接.这样操作会浪费资源 使用连接池,主要的区别在于,不需要中断物理连接,即每次中断请求时spid还是存在! 原 ...
- opencv载入,显示及保存图像
1.声明一个表示图像的变量,在OpenCV2中,这个变量是cv::Mat类型,该类是用于保存图像以及其他矩阵数据的数据结构.默认情况下它们的尺寸为0. cv::Mat image; // ...
- 一个容易被忽略的ReportingService超时问题
我们在使用Sql Server Reporting Service开发报表的时候,经常会遇到报表超时的问题,报表超时的原因有很多,也有很多地方可以设置报表的超时时间,比如在报表中的数据源(dataso ...
- 在ASP.NET非MVC环境中(WebForm中)构造MVC的URL参数
目前项目中有个需求,需要在WebForm中去构造MVC的URL信息,这里写了一个帮助类可以在ASP.NET非MVC环境中(WebForm中)构造MVC的URL信息,主要就是借助当前Http上下文去构造 ...