转载请注明出自天外归云的博客园: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级别的导航菜单的更多相关文章

  1. Bing Maps进阶系列七:Bing Maps功能导航菜单华丽的变身

    Bing Maps进阶系列七:Bing Maps功能导航菜单华丽的变身 Bing Maps Silverlight Control所提供的功能导航是非常强大的,在设计上对扩展的支持非常好,提供了许多用 ...

  2. SharePoint自动化系列——Add content type to list.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...

  3. SharePoint自动化系列——Upload files to SharePoint library using PowerShell.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的 ...

  4. SharePoint自动化系列——Select-option标签的定位方法总结

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ C#中通过Selenium定位页面上的select-option结构,尝试了以下几种方法,均没有生 ...

  5. SharePoint 2013技巧分享系列 - 隐藏Blog和Apps左侧导航菜单

    企业内部网中,不需要员工创建Blog或者创建,安装SharePoint应用,因此需要在员工个人Web页面需要隐藏Blog或者Apps导航菜单, 其步骤设置如下: 该技巧适合SharePoint 201 ...

  6. SharePoint自动化系列——通过PowerShell创建SharePoint Web

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

  7. SharePoint自动化系列——通过PowerShell创建SharePoint Site Collection

    通过PowerShell创建SharePoint Site Collection,代码如下: Add-PSSnapin microsoft.sharepoint.powershell function ...

  8. SharePoint自动化系列——Manage "Site Subscriptions" using PowerShell

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 你可以将普通的sites加入到你的site subscriptions中,前提是你需要有一个 Te ...

  9. SharePoint自动化系列——Create a local user and add to SharePoint

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 实现过程:在本地创建一个local user并将该user添加到Administrators组中, ...

随机推荐

  1. [原创]java WEB学习笔记88:Hibernate学习之路-- -Hibernate检索策略(立即检索,延迟检索,迫切左外连接检索)

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  2. vs2003打包

    怎样将.Net程序部署到没有安装.Net Framwork的机器上? 部署在.Net 平台下开发的应用程序,需要安装安装对应版本的.Net Framwork,而Vsual Studio 2003并没有 ...

  3. 。。。无语的Eclipse+Tomact。。。

    晕哦,今天又被Eclipse给骗了,今天部署了一个SSH的环境,搞了半天,JAR包是通过BuildPath导入进去的,怎么搞都报错,说是找不到Spring-Web的一个Jar包,差点没有把我给弄死.. ...

  4. 深度解析 Java 内存原型

    一.Java 虚拟机内存原型 寄存器:我们在程序中无法控制. 栈:存放基本类型的数据和对象的引用,但对象本身不存放在栈中,而是存放在 堆中. 堆:存放用 new 产生的数据. 静态域:存放在对象中用  ...

  5. struts局部、全局类型转换器

    第01步:编写bean package com.self.bean; import java.util.Date; public class User { private Date birthday ...

  6. android中影藏状态栏和标题栏的几种方法

    1,在android中,有时候我们想隐藏我们的状态栏和标题栏(如:第一次安装app时候的欢迎界面),实现这些效果有几种方法,随便选取自己喜欢的即可. 2, A:利用代码实现,在我们主Activity中 ...

  7. 夺命雷公狗---DEDECMS----3快速入门之隐藏

    如果我们在工作的时候遇到上操蛋的老板,本来公司是做医疗器械的,但是老板突然老了句我们不做医疗了,我们该做电影网,那么我们可以先将原本的栏目进行修改成隐藏栏目, 主要是预防变态老板突然来句“电影网更不好 ...

  8. 8007003Windows Update遇到未知错误

    如果在检查更新时收到 Windows Update 错误 80070003,则需要删除 Windows 用于标识计算机更新的临时文件.若要删除临时文件,请停止 Windows Update 服务,删除 ...

  9. Asp.net中后台C#数组与前台Javascript数组交互

    摘自:http://blog.csdn.net/a6225301/article/details/20003305 在上一篇<asp.net中javascript与后台c#交互>中实现了前 ...

  10. empty()、html("")和text("")

    empty().html("")和text("")在删除匹配元素内内容时是一样的.jQuery源码中实现有所不同,但效果相同.可以测试一下源码: <!DO ...