转载请注明出自天外归云的博客园: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. FB面经prepare: task schedule II

    followup是tasks是无序的. 一开始是有序的,比如说1, 1, 2, 1,一定要先执行第一个task1,然后等task1恢复,再执行第2个task1,再执行task2..... follow ...

  2. nyist 506 洗澡

    http://acm.nyist.net/JudgeOnline/problem.php?pid=506 洗澡 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 Mos ...

  3. Eclipse安装Ruby插件应该注意的几点

    http://www.aptana.com/products/studio3/success_plugin.html Installing via Eclipse Please copy the fo ...

  4. android waiting for debugger

    在Studio开发环境中,使用真机开发经常会出现waiting for debugger,卡死不动了,让人很崩溃啊,现在我就总结下几种解决方法,希望能帮到出现同样情况的朋友! 问题出现及解决办法: 多 ...

  5. RMAN命令

    一.启动.关闭数据库 在RMAN中执行关闭和启动数据库的命令与SQL环境下一模一样.当然,在执行之前,你需要先连接到目标数据库,如例: C:\Documents and Settings\Admini ...

  6. Android SDK Manager更新报错

    错误log: Fetching https://dl-ssl.google.com/android/repository/addons_list-.xml Fetched Add-ons List s ...

  7. 真实的C++单例模式举例

    把构造函数声明为protected的理由很简单,但把构造函数声明为private的原因却很少知道.   从语法上讲,任何函数如果被声明为private,这个函数就不能从外部调用,构造函数也是函数,相反 ...

  8. spring支持的websocket

    首发:个人博客 必须说明:这篇博文只用于自己记录,使用spring的websocket支持一定要看官方文档,权威又简明,不推荐看不专业又啰嗦的国产博文. 已尝试了两种方法,当然,不管哪种方法都要先添加 ...

  9. 关闭 Windows 的常用端口

    netstat -ano 可以看到目前开着哪些端口 netstat -ano|findstr <端口号>   可以找到开放的端口的那条,最后还列出了 PID. 然后到任务管理器中,你可以查 ...

  10. word2007里插入分节符

    1.打开Word文档,将鼠标定位到需要插入分页符的位置(比如第2页的末尾处),切换到"页面布局"功能区. 2.在"页面设置"分组中单击"分隔符&quo ...