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组中, ...
随机推荐
- oracle 复杂语句
select nvl(sum1,'0')as sum1,nvl(sum2,'0') as sum2,da2 from( select count(*) as sum1,substr(APPLY_DAT ...
- cookie和session区别
cookie和session区 session是在服务器端保存用户信息,cookie是在客户端保存用户信息 session保存的是对象,cookie保存的是字符串 session会随回话结束而关闭,c ...
- PHP中9大缓存技术总结(转载 http://www.php100.com/html/php/lei/2015/0919/8969.html)
PHP中9大缓存技术总结 来源: 时间:2015-09-19 02:40:33 阅读数:57767 分享到: 12 [导读] 1.全页面静态化缓存也就是将页面全部生成html静态页面,用户访问 ...
- Android -- 自定义View小Demo,绘制钟表时间(一)
1,昨天刚看了hongyang大神推荐的自定义时钟效果(传动门:http://www.jianshu.com/users/a45d19d680af/),效果还是不错的,自己又在github上找了找,发 ...
- js高级程序设计笔记之-addEventListener()与removeEventListener(),事件解除与绑定
js高级程序设计笔记之-addEventListener()与removeEventListener(),事件解除与绑定 addEventListener()与removeEventListener( ...
- YbRapidSolution.MVC项目首页分页没有起作用
@model YbRapidSolution.Mvc.Models.CmsPagerDataModel <nav> <ul class="pager"> & ...
- lower power设计中的DVFS设计
Pswitch = Ceff * Vvdd^2*Fclk, Pshort-circuit = Isc * Vdd * Fclk, Pleakage = f(Vdd, Vth, W/L) 尽管对电压的s ...
- 作为一个web开发人员,哪些技术细节是在发布站点前你需要考虑到的
前日在cnblogs上看到一遍文章<每个程序员都必读的12篇文章>,其中大多数是E文的. 先译其中一篇web相关的”每个程序员必知之WEB开发”. 原文: http://programme ...
- Android webview实现上传图片的效果(图片压缩)
mainactivity代码 package com.bwie.webviewupload; import java.io.ByteArrayInputStream; import java.io.B ...
- filesort是什么意思?
我们碰到有order by 或者group by,或者distinct语句的时候,如果查看执行计划,通常会看到using filesort的字眼,那么这个filesort是不是真是文件排序呢?其实不然 ...