powershell 此PowerShell脚本创建三个SharePoint列表并添加字段
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 此PowerShell脚本创建三个SharePoint列表并添加字段相关的知识,希望对你有一定的参考价值。
#
Add-PsSnapin Microsoft.SharePoint.PowerShell
$webURL = "http://scusp4:14700"
$spSite = [Microsoft.SharePoint.SPSite]($webURL)
$spWeb = $spSite.OpenWeb()
#
# Create a custom list (ID is 100)
$myListGuid = $spWeb.Lists.Add("EmployeeInfo", "Employee Information", 100)
$myList = $spweb.Lists[$myListGuid]
#
# Adding user fields
$myFieldCustomerAvailable = $myList.Fields.Add("User", "User", 0)
$myList.Fields[$myFieldCustomerAvailable].Title = “Customer Available”
$myList.Fields[$myFieldCustomerAvailable].Update()
#
# Adding Text fields
$myFieldCustomerName = $myList.Fields.Add("OrgCode", "Text", 0)
$myList.Fields[$myFieldCustomerName].Title = "OrgCode"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding Text fields
$myFieldCustomerName = $myList.Fields.Add("OrgName", "Text", 0)
$myList.Fields[$myFieldCustomerName].Title = "OrgName"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding Text fields
$myFieldCustomerName = $myList.Fields.Add("Email", "Text", 0)
$myList.Fields[$myFieldCustomerName].Title = "Email"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("YearlyVacationAllocation", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "YearlyVacationAllocation"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("VacationCarryForwardAllowed", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "VacationCarryForwardAllowed"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("TotalVacationAllowed", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "TotalVacationAllowed"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("CurrentYearAvailableVacTime", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "CurrentYearAvailableVacTime"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("YTDVacationUsed", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "YTDVacationUsed"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("YTDVacationTimeBalance", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "YTDVacationTimeBalance"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("YearlySickLeaveAllowed", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "YearlySickLeaveAllowed"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("YTDSickLeaveUsed", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "YTDSickLeaveUsed"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("YTDSickLeaveBalance", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "YTDSickLeaveBalance"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("YearlyPersonalLeaveAllowed", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "YearlyPersonalLeaveAllowed"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("YTDPersonalLeaveUsed", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "YTDPersonalLeaveUsed"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding number fields
$myFieldCustomerName = $myList.Fields.Add("YTDPersonalLeaveBalance", "Number", 0)
$myList.Fields[$myFieldCustomerName].Title = "YTDPersonalLeaveBalance"
$myList.Fields[$myFieldCustomerName].Update()
#
# Adding Date fields
##$myFieldCustomerDate = $myList.Fields.Add(“CustomerDate”, “DateTime”, 0)
##$myList.Fields[$myFieldCustomerDate].Title = “Customer Date”
##$myList.Fields[$myFieldCustomerDate].DisplayFormat = “DateOnly”
##$myList.Fields[$myFieldCustomerDate].Update()
$myList.OnQuickLaunch = $True
$myList.Update()
#
##########Second List#####################
# Create a custom list (ID is 100)
$myListGuidAD = $spWeb.Lists.Add("AbsenceRequestDates", "AbsenceRequestDates", 100)
$myListAD = $spweb.Lists[$myListGuidAD]
#
# Adding user fields
$myFieldCustomerAvailable = $myListAD.Fields.Add("User", "User", 0)
$myListAD.Fields[$myFieldCustomerAvailable].Title = "User"
$myListAD.Fields[$myFieldCustomerAvailable].Update()
#
# Adding Date fields
$myFieldCustomerDate = $myListAD.Fields.Add("Date", "DateTime", 0)
$myListAD.Fields[$myFieldCustomerDate].Title = "Date”
$myListAD.Fields[$myFieldCustomerDate].DisplayFormat = "DateOnly"
$myListAD.Fields[$myFieldCustomerDate].Update()
#
# Adding number fields
$myFieldCustomerName = $myListAD.Fields.Add("Hours", "Number", 0)
$myListAD.Fields[$myFieldCustomerName].Title = "Hours"
$myListAD.Fields[$myFieldCustomerName].Update()
#
# Adding Text fields
$myFieldCustomerName = $myListAD.Fields.Add("LeaveType", "Text", 0)
$myListAD.Fields[$myFieldCustomerName].Title = "LeaveType"
$myListAD.Fields[$myFieldCustomerName].Update()
#
$myListAD.OnQuickLaunch = $True
$myListAD.Update()
#
##########Third List#####################
# Create a custom list (ID is 100)
$myListGuidRRD = $spWeb.Lists.Add("RestrictedandReservedDates", "Restricted and Reserved Dates", 100)
$myListRRD = $spweb.Lists[$myListGuidRRD]
#
# Adding Text fields
$myFieldCustomerName = $myListRRD.Fields.Add("LeaveType", "Text", 0)
$myListRRD.Fields[$myFieldCustomerName].Title = "LeaveType"
$myListRRD.Fields[$myFieldCustomerName].Update()
#
# Adding Date fields
$myFieldCustomerDate = $myListRRD.Fields.Add("Dates", "DateTime", 0)
$myListRRD.Fields[$myFieldCustomerDate].Title = "Dates”
$myListRRD.Fields[$myFieldCustomerDate].DisplayFormat = "DateOnly"
$myListRRD.Fields[$myFieldCustomerDate].Update()
#
# Adding Text fields
$myFieldCustomerName = $myListRRD.Fields.Add("OrganizationCode", "Text", 0)
$myListRRD.Fields[$myFieldCustomerName].Title = "Organization Code"
$myListRRD.Fields[$myFieldCustomerName].Update()
#
# Adding Text fields
$myFieldCustomerName = $myListRRD.Fields.Add("OrganizationName", "Text", 0)
$myListRRD.Fields[$myFieldCustomerName].Title = "Organization Name"
$myListRRD.Fields[$myFieldCustomerName].Update()
#
$myListRRD.OnQuickLaunch = $True
$myListRRD.Update()
$spWeb.Dispose()
$spSite.Dispose()
以上是关于powershell 此PowerShell脚本创建三个SharePoint列表并添加字段的主要内容,如果未能解决你的问题,请参考以下文章
powershell 此powershell脚本使用字段名称获取所有值是sharepoint列表中的字段
powershell 此PowerShell脚本从子站点组等于值的所有子站点中删除组。如果要删除gro,请使用此选项
powershell 此PowerShell脚本是从SCCM DB获取SCEP日志并将其导出为CSV文件
powershell 此powershell脚本生成新证书,从IISExpress ssl端口删除旧证书分配并添加新证书
powershell 使用PowerShell导出MSSQL架构。此脚本将导出表,存储过程,触发器,函数和视图的模式定义