SharePoint网站测试数据自动化系列——通过PowerShell创建SharePoint List Items

代码如下(保存到本地ps1文件中,右键run with PowerShell即可):

Add-PSSnapin microsoft.sharepoint.powershell
function CreateSPListItems()
{
    $sites = Get-SPSite
    if($sites.count -eq 0)
    {
        Write-Warning "There is no site available."
        CreateSPListItems
    }
    else
    {
        Write-Host "Choose the site:" -ForegroundColor Yellow
        for($i=0;$i -lt $sites.count;$i++)
        {
            $tip = "["+$i+"]."+$sites[$i].url
            Write-Host $tip
        }
        $choice = Read-Host "Enter the number before"
        $tip = "You chose "+$choice+". "+"The site you chose is ‘"+$sites[[int]$choice].url+"‘"
        Write-Host $tip -ForegroundColor Green
        Write-Host "Choose the web:" -ForegroundColor Yellow
        $webs = $sites[[int]$choice].AllWebs
        for($i=0;$i -lt $webs.count;$i++)
        {
            $tip = "["+$i+"]."+$webs[$i].url
            Write-Host $tip
        }
        $choice = Read-Host "Enter the number before"
        $tip = "You chose "+$choice+". "+"The web you chose is ‘"+$webs[[int]$choice].url+"‘"
        Write-Host $tip -ForegroundColor Green
        $lists = $webs[[int]$choice].lists
        if($lists.count -eq 0)
        {
            Write-Warning "There is no list available."
            CreateSPListItems
        }
        else
        {
            Write-Host "Choose the list:" -ForegroundColor Yellow
            for($i=0;$i -lt $lists.count;$i++)
            {
                $tip = "["+$i+"]."+$lists[$i].title
                Write-Host $tip
            }
            $choice = Read-Host "Enter the number before"
            $tip = "You chose "+$choice+". "+"The web you chose is ‘"+$webs[[int]$choice].url+"‘"
            $list = $lists[[int]$choice]
            $tip = "The list you chose is ‘" + $list.title +"‘"
            Write-Host $tip -ForegroundColor Green
            $amount = Read-Host "How many items do you want to create"
            $titleEp = Read-Host "Give an example of the item title, such as ‘tylan‘"
            for($i=1;$i -le $amount;$i++){
                $random = Get-Random 10000
                $sign = $date.month+$date.day+$date.hour+$date.minute+$date.second+$random
                $newItem = $List.Items.Add()
                $newItem["Title"] = $sign.ToString() + $titleEp + "TestData"
                $newItem.Update()
            }
            $tip = "Items have been created successfully under the list ‘"+$list.title+"‘."
            Write-Host $tip -ForegroundColor Green
            $choice = Read-Host "Press ‘c‘ to continue"
            if($choice -eq ‘c‘)
            {
                CreateSPListItems
            }
        }
    }
}
CreateSPListItems

运行界面:

时间: 2024-08-01 10:46:22

SharePoint网站测试数据自动化系列——通过PowerShell创建SharePoint List Items的相关文章

SharePoint网站测试数据自动化系列——通过PowerShell创建SharePoint Lists

代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin microsoft.sharepoint.powershell function CreateSPLists() { $sites = Get-SPSite if($sites.count -eq 0) { Write-Warning "There is no site available." CreateSPLists } else { Write-Host "C

SharePoint网站测试数据自动化系列——Upload files to SharePoint library using PowerShell.

日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的脚本越来越多,所以我决定整理一下,并把一些常用的可复用的方法陆续发布上来. 今天先讲一下用PowerShell上传文件到SharePoint library中的方法,代码如下: Add-PSSnapin Microsoft.SharePoint.PowerShell function CreateAgendaDocumentData { param($siteUrl,$listTitle,$file

使用PowerShell 创建SharePoint 网站

使用PowerShell 创建SharePoint 网站 在SharePoint开发中,你应该学会使用PowerShell管理SharePoint站点.SharePoint Management Shell是一个Windows PowerShell模块,你可以用它高效管理SharePoint 用户.站点.网站集和组织. 这里教你简单的语句,创建一个SharePoint网站. 输入一下语句.红色框内信息是按下Enter后出现的. 建立的网站如下: 首先我们需要理解如何使用PowerShell创建站

通过PowerShell创建SharePoint Site Collection。

通过PowerShell创建SharePoint Site Collection,代码如下: Add-PSSnapin microsoft.sharepoint.powershell function CreateTeamSite() { $webApps = Get-SPWebApplication $webAppsUrl = $webApps.Url if($webApps.count -eq 1) { Write-Host "You have only one web applicatio

通过PowerShell创建SharePoint Web

代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin Microsoft.SharePoint.PowerShell function createSPWeb() { $webApps = Get-SPWebApplication chooseWebAppAndSelectSite $webApps } function chooseWebAppAndSelectSite($webApps) { Write-Host "Web appli

PowerShell创建SharePoint 权限等级

参考:https://social.technet.microsoft.com/wiki/contents/articles/18661.sharepoint-2010-update-a-permission-level-using-powershell.aspx $sites = get-spsite -Limit ALL –webapplication http://mywebapplication.com ForEach ($site in $Sites) { # The URL to t

转载 SharePoint【Site Definition 系列】– 创建Content Type

转载原地址:  http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面存储的所有信息我们可以称其为“内容(Content)”,为了便于管理这些Conent,按照人类的正常逻辑就必然想到的是对此进行“分类”.分类所涉及到的层面又必然包括: 1.分类的标准或特征描述{即:类型属性(或:与该类型项目相关联的属性)}. 2.对应类的关联动作(即:工作流,行为以及其他设置)  

SharePoint 2013 图文开发系列之网站栏

原文:SharePoint 2013 图文开发系列之网站栏 网站栏的本质,就是一个xml的描述文件,所以创建过程,基本就是通过Feature部署一个Xml文件,然后修改Xml文件的网站栏描述. 1.添加新项目,选择SharePoint 2013 空项目,如下图: 2.选择调试网站和解决方案类型,这里选择场,如下图: 3.添加新项,选择网站栏,如下图: 4.修改网站栏的Feature文件,方便以后识别,如下图: 5.查看网站栏的Xml文件,这是一个默认的单行文本类型,我们准备创建一个选项类型: 6

SharePoint 2013 图文开发系列之创建内容类型

原文:SharePoint 2013 图文开发系列之创建内容类型 SharePoint内容类型,是很有特色的,就好比发布新闻,同在一张列表里,可以由内容类型区分图片新闻.文字新闻等,顾名思义,就是在一张列表里发布不同类型的项目. 1.添加新项目,选择SharePoint 2013 空项目,如下图: 2.选择调试网站和解决方案类型,如下图: 3.添加新项,选择内容类型,如下图: 4.选择继承的父内容类型,如下图: 5.修改内容类型的Feature文件,如下图: 6.查看内容类型的xml文件,如下图