powershell 这是一个脚本,可以在列表中创建网站集,网站,列表和项目。它旨在模拟一个大的创造
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 这是一个脚本,可以在列表中创建网站集,网站,列表和项目。它旨在模拟一个大的创造相关的知识,希望对你有一定的参考价值。
#powershell script for creating test site collections, web sites, and lists:
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }
function randomChar($length)
{
$PasswordLength = $length
$InclChars = ‘abcdefghkmnprstuvwxyzABCDEFGHKLMNPRSTUVWXYZ123456789’
$RandomChar = 1..$PasswordLength | ForEach-Object { Get-Random -Maximum $InclChars.length }
$RandomPassowrdChar = [String]$InclChars[$RandomChar]
return $RandomPassowrdChar.Replace(" ","")
}
function randomNumber($length)
{
$PasswordLength = $length
$InclNums = "123456789"
$RandomNums = 1..$PasswordLength | ForEach-Object { Get-Random -Maximum $InclNums.length }
$RandomPassowrd = [String]$InclNums[$RandomNums]
return $RandomPassowrd.Replace(" ","")
}
#start-transcript -Path C:\SharePoint -NoClobber -append
#Loop through 1-40 create site collections /depts/c##
$i = 0
$StartSiteCollectNumber = 1 #starting site collection number
$numSiteCollections = 5
$numWebSites = 20
$numLists = 10
$numItems = 1000
$siteCollectionOwner = "PSNS\Mike"
$secondaryOwnerAlias = "PSNS\SPAdmin2010"
$webApp = "http://sp2010"
$databaseServer = "SP2010SQL\SP2010"
#site collections
for($i -eq $StartSiteCollectNumber;$i -lt $numSiteCollections; $i++){
$newSiteCollectionURL = "http://sp2010/sites/C" + $i
$contentDBName = "WSS_Content_C" + $i
$contentDB = New-SPContentDatabase -Name $contentDBName -WebApplication $webApp
write-host "Create site collection DB $contentDBName" -foregroundcolor Red -backgroundcolor Yellow
$siteCollectionName = "C" + $i
Get-SPWebTemplate | Where{ $_.Title -eq "Team Site" } | ForEach-Object{ New-SPSite $newSiteCollectionURL -OwnerAlias $siteCollectionOwner -SecondaryOwnerAlias $secondaryOwnerAlias -ContentDatabase $contentDBName -Name $siteCollectionName -Template $_ }
write-host "Created site collection C $i" -foregroundcolor Red -backgroundcolor Yellow
#websites
$x = 0
for($x -eq 0;$x -lt $numWebSites;$x++){
#each site collection create web sites 1-40 /depts/c##/webW##
$newWebSiteURL = $newSiteCollectionURL + "/Code" + $x
$webSiteName = "/Code $x"
write-host "Create web site code $x" -foregroundcolor Black -backgroundcolor green
Get-SPWebTemplate | Where{ $_.Title -eq "Team Site" } | ForEach-Object{$temp = New-SPWeb $newWebSiteURL -Template $_ -Name $webSiteName}
#lists
$y = 0
for($y -eq 0;$y -lt $numLists; $y++){
#each web site create lists
$listName = "Lister" + $y
write-host "Create list:" + $listName -foregroundcolor White -backgroundcolor DarkBlue
$spWeb = Get-SPWeb -Identity $newWebSiteURL
$spTemplate = $spWeb.ListTemplates["Custom List"]
$spListCollection = $spWeb.Lists
$temp = $spListCollection.Add($listName, "Text list" + $y, $spTemplate)
#Add list columns Columns: testText1, testNumber1,testText2, testNumber2
$myCustomList = $spWeb.Lists[$listName]
$testText1ColXml = "<Field Type='Text' DisplayName='testText1' Required='FALSE' MaxLength='255'
StaticName='testText1' Name='testText1' />"
$myCustomList.Fields.AddFieldAsXml($testText1ColXml)
$testText2ColXml = "<Field Type='Text' DisplayName='testText2' Required='FALSE' MaxLength='255'
StaticName='testText2' Name='testText2' />"
$temp = $myCustomList.Fields.AddFieldAsXml($testText2ColXml)
$testNumber1 = "<Field Type='Number' DisplayName='testNumber1' Required='FALSE' Name='testNumber1'/>"
$temp = $myCustomList.Fields.AddFieldAsXml($testNumber1)
$testNumber2 = "<Field Type='Number' DisplayName='testNumber2' Required='FALSE' Name='testNumber2'/>"
$temp = $myCustomList.Fields.AddFieldAsXml($testNumber2)
write-host "Added fields to:" $listName -foregroundcolor Black -backgroundcolor Cyan
#even numbers only get the date field
if($y % 2 -eq 0 ){
$temp = $myCustomList.Fields.Add("CalculatedDateField", "Calculated", 0)
$SPField = $myCustomList.Fields.GetField("CalculatedDateField")
$SPField.Formula="=Today()"
$SPField.OutputType="DateTime"
$SPField.Update()
}
#add data to the custom lists
write-host "Adding list items" -foregroundcolor White -backgroundcolor DarkGreen
$z = 0
#items
for($z -eq 0;$z -lt $numItems; $z++){
$ItemTitle = "Item" + $z
$testText1 = randomChar(5)
$testText2 = randomChar(10)
#randomNumber(3)
$testNumber1 = randomNumber(3)
$testNumber2 = randomNumber(5)
$newItem = $myCustomList.AddItem()
$newItem["Title"] = $ItemTitle
$newItem["testText1"] = $testText1
$newItem["testText2"] = $testText2
$newItem["testNumber1"] = $testNumber1
$newItem["testNumber2"] = $testNumber2
$newItem.Update()
}#list Items
write-host "Completed adding list items" -foregroundcolor White -backgroundcolor DarkGreen
}#lsits
}#websites
}#site collections
#Dispose web
#$web.Dispose()
#stop-transcript
#powershell script for creating test site collections, web sites, and lists:
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }
function randomChar($length)
{
$PasswordLength = $length
$InclChars = ‘abcdefghkmnprstuvwxyzABCDEFGHKLMNPRSTUVWXYZ123456789’
$RandomChar = 1..$PasswordLength | ForEach-Object { Get-Random -Maximum $InclChars.length }
$RandomPassowrdChar = [String]$InclChars[$RandomChar]
return $RandomPassowrdChar.Replace(" ","")
}
function randomNumber($length)
{
$PasswordLength = $length
$InclNums = "123456789"
$RandomNums = 1..$PasswordLength | ForEach-Object { Get-Random -Maximum $InclNums.length }
$RandomPassowrd = [String]$InclNums[$RandomNums]
return $RandomPassowrd.Replace(" ","")
}
#Loop through 1-40 create site collections /depts/c##
$i = 0
$end = 2
for($i -eq 0;$i -lt $end; $i++){
$newSiteCollectionURL = "http://sharepoint/depts/C" + $i
Get-SPWebTemplate | Where{ $_.Title -eq "Team Site" } | ForEach-Object{ New-SPSite $newSiteCollectionURL -OwnerAlias contoso\mike -Template $_ }
write-host "Create site collection C" + $i -foregroundcolor Red -backgroundcolor Yellow
$x = 0
for($x -eq 0;$x -lt $end;$x++){
#each site collection create web sites 1-40 /depts/c##/webW##
$newWebSiteURL = $newSiteCollectionURL + "/Code" + $x
write-host "Create web site code" + $x -foregroundcolor Black -backgroundcolor green
Get-SPWebTemplate | Where{ $_.Title -eq "Team Site" } | ForEach-Object{$temp = New-SPWeb $newWebSiteURL -Template $_ }
$y = 0
for($y -eq 0;$y -lt $end; $y++){
#each web site create lists
$listName = "Lister" + $y
write-host "Create list:" + $listName -foregroundcolor White -backgroundcolor DarkBlue
$spWeb = Get-SPWeb -Identity $newWebSiteURL
$spTemplate = $spWeb.ListTemplates["Custom List"]
$spListCollection = $spWeb.Lists
$temp = $spListCollection.Add($listName, "Text list" + $y, $spTemplate)
#Add list columns Columns: testText1, testNumber1,testText2, testNumber2
$myCustomList = $spWeb.Lists[$listName]
$testText1ColXml = "<Field Type='Text' DisplayName='testText1' Required='FALSE' MaxLength='255'
StaticName='testText1' Name='testText1' />"
$myCustomList.Fields.AddFieldAsXml($testText1ColXml)
$testText2ColXml = "<Field Type='Text' DisplayName='testText2' Required='FALSE' MaxLength='255'
StaticName='testText2' Name='testText2' />"
$temp = $myCustomList.Fields.AddFieldAsXml($testText2ColXml)
$testNumber1 = "<Field Type='Number' DisplayName='testNumber1' Required='FALSE' Name='testNumber1'/>"
$temp = $myCustomList.Fields.AddFieldAsXml($testNumber1)
$testNumber2 = "<Field Type='Number' DisplayName='testNumber2' Required='FALSE' Name='testNumber2'/>"
$temp = $myCustomList.Fields.AddFieldAsXml($testNumber2)
write-host "Added fields to:" $listName -foregroundcolor Black -backgroundcolor Cyan
#even numbers only get the date field
if($y % 2 -eq 0 ){
$temp = $myCustomList.Fields.Add("CalculatedDateField", "Calculated", 0)
$SPField = $myCustomList.Fields.GetField("CalculatedDateField")
$SPField.Formula="=Today()"
$SPField.OutputType="DateTime"
$SPField.Update()
}
#add data to the custom lists
$z = 0
for($z -eq 0;$z -lt $end; $z++){
$ItemTitle = "Item" + $z
$testText1 = randomChar(5)
$testText2 = randomChar(10)
randomNumber(3)
$testNumber1 = randomNumber(3)
$testNumber2 = randomNumber(5)
$newItem = $myCustomList.AddItem()
$newItem["Title"] = $ItemTitle
$newItem["testText1"] = $testText1
$newItem["testText2"] = $testText2
$newItem["testNumber1"] = $testNumber1
$newItem["testNumber2"] = $testNumber2
$newItem.Update()
write-host "Added list item:" + $ $ItemTitle -foregroundcolor White -backgroundcolor DarkGreen
}#list Items
}#lsits
}#websites
}#site collections
#Dispose web
#$web.Dispose()
#powershell script for creating test site collections, web sites, and lists:
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }
function randomChar($length)
{
$PasswordLength = $length
$InclChars = ‘abcdefghkmnprstuvwxyzABCDEFGHKLMNPRSTUVWXYZ123456789’
$RandomChar = 1..$PasswordLength | ForEach-Object { Get-Random -Maximum $InclChars.length }
$RandomPassowrdChar = [String]$InclChars[$RandomChar]
return $RandomPassowrdChar.Replace(" ","")
}
function randomNumber($length)
{
$PasswordLength = $length
$InclNums = "123456789"
$RandomNums = 1..$PasswordLength | ForEach-Object { Get-Random -Maximum $InclNums.length }
$RandomPassowrd = [String]$InclNums[$RandomNums]
return $RandomPassowrd.Replace(" ","")
}
#Loop through 1-40 create site collections /depts/c##
$i = 0
$numSiteCollections = 1
$numWebSites = 100
$numLists = 100
$numItems = 1000
$siteCollectionOwner = 'PSNS\Administrator'
#site collections
for($i -eq 0;$i -lt $numSiteCollections; $i++){
$newSiteCollectionURL = "http://spsvde001/sites/C" + $i
Get-SPWebTemplate | Where{ $_.Title -eq "Team Site" } | ForEach-Object{ New-SPSite $newSiteCollectionURL -OwnerAlias $siteCollectionOwner -Template $_ }
write-host "Create site collection C" + $i -foregroundcolor Red -backgroundcolor Yellow
#websites
$x = 0
for($x -eq 0;$x -lt $numWebSites;$x++){
#each site collection create web sites 1-40 /depts/c##/webW##
$newWebSiteURL = $newSiteCollectionURL + "/Code" + $x
write-host "Create web site code" + $x -foregroundcolor Black -backgroundcolor green
Get-SPWebTemplate | Where{ $_.Title -eq "Team Site" } | ForEach-Object{$temp = New-SPWeb $newWebSiteURL -Template $_ }
#lists
$y = 0
for($y -eq 0;$y -lt $numLists; $y++){
#each web site create lists
$listName = "Lister" + $y
write-host "Create list:" + $listName -foregroundcolor White -backgroundcolor DarkBlue
$spWeb = Get-SPWeb -Identity $newWebSiteURL
$spTemplate = $spWeb.ListTemplates["Custom List"]
$spListCollection = $spWeb.Lists
$temp = $spListCollection.Add($listName, "Text list" + $y, $spTemplate)
#Add list columns Columns: testText1, testNumber1,testText2, testNumber2
$myCustomList = $spWeb.Lists[$listName]
$testText1ColXml = "<Field Type='Text' DisplayName='testText1' Required='FALSE' MaxLength='255'
StaticName='testText1' Name='testText1' />"
$myCustomList.Fields.AddFieldAsXml($testText1ColXml)
$testText2ColXml = "<Field Type='Text' DisplayName='testText2' Required='FALSE' MaxLength='255'
StaticName='testText2' Name='testText2' />"
$temp = $myCustomList.Fields.AddFieldAsXml($testText2ColXml)
$testNumber1 = "<Field Type='Number' DisplayName='testNumber1' Required='FALSE' Name='testNumber1'/>"
$temp = $myCustomList.Fields.AddFieldAsXml($testNumber1)
$testNumber2 = "<Field Type='Number' DisplayName='testNumber2' Required='FALSE' Name='testNumber2'/>"
$temp = $myCustomList.Fields.AddFieldAsXml($testNumber2)
write-host "Added fields to:" $listName -foregroundcolor Black -backgroundcolor Cyan
#even numbers only get the date field
if($y % 2 -eq 0 ){
$temp = $myCustomList.Fields.Add("CalculatedDateField", "Calculated", 0)
$SPField = $myCustomList.Fields.GetField("CalculatedDateField")
$SPField.Formula="=Today()"
$SPField.OutputType="DateTime"
$SPField.Update()
}
#add data to the custom lists
$z = 0
#items
for($z -eq 0;$z -lt $numItems; $z++){
$ItemTitle = "Item" + $z
$testText1 = randomChar(5)
$testText2 = randomChar(10)
randomNumber(3)
$testNumber1 = randomNumber(3)
$testNumber2 = randomNumber(5)
$newItem = $myCustomList.AddItem()
$newItem["Title"] = $ItemTitle
$newItem["testText1"] = $testText1
$newItem["testText2"] = $testText2
$newItem["testNumber1"] = $testNumber1
$newItem["testNumber2"] = $testNumber2
$newItem.Update()
write-host "Added list item:" + $ $ItemTitle -foregroundcolor White -backgroundcolor DarkGreen
}#list Items
}#lsits
}#websites
}#site collections
#Dispose web
#$web.Dispose()
以上是关于powershell 这是一个脚本,可以在列表中创建网站集,网站,列表和项目。它旨在模拟一个大的创造的主要内容,如果未能解决你的问题,请参考以下文章
powershell 这将在sharepoint中创建一个新的自定义列表
在 Powershell 中创建 PerformanceCounterCategory