#*************************************************************************************************************************************
# File name : AllFunctionToList.ps1
# Created by : v-trdong 2012/10/30
# This script is for uploading the custom list tempalte, and create a list by the custom list tempalte,then operate the list.
# the paramters are follow:
# $spSite: The website url you want to operate, example
http://localhost
# $spweb : The web url you want to upload the file, example
http://localhost
# $spList: The list you want to operate
# $file : The file path that relative to this script, example MyTemplate.stp
# $folder : The upolad folder path which related to the web, example _catalogs/It
# $dir : The path of the current script file
# $source : The source url you want to download file
# $destination : The path in disk you want to put
# Note: If there is a existing file name, the old file will be overwrited,please make sure the file need to be uploaded in the same folder of this script
#***************************************************************************************************************************************
# Import the Microsoft.SharePoint.PowerShell
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
# Upload the list template
# Example: UpLoadTemplate "http://localhost" "MyTemplate.stp" "template.stp"
function UpLoadTemplate($spSite,$path,$Name){
# Get the root web, only the root web contains list templates
$spSite=Get-SPSite -Identity $spSite
$spWeb=$spSite.RootWeb
try{
# Get the site page of the template sitepage
$spFolder = $spWeb.GetFolder("_catalogs/It")
$spFileCollection = $spFolder.Files
# Get the path of the file you want to upload
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
$dir=Split-Path $Invocation.MyCommand.Path
$path = $dir+"\"+$path
# Check the path
If(Test-Path "$path"){
$file=Get-ChildItem $path
# Add the file
$spFileCollection.Add("/_catalogs/lt/"+$Name,$file.OpenRead(),$true)
}
else{
# If the path is not right, throw the exception
write-host "The path is wrong"
throw
}
}
catch{
write-host "(ERROR : "$_.Exception.Message")"
throw
}
finally{
if($spWeb -eq $null){
write-host "The web site is not existing"
}
else{
$spWeb.Dispose()
}
}
}
# Create a list by the custom list template
# Example: CreateCustomList "http://localhost" "MyTemplate" "MyNewList" "This is my list"
function CreateCustomList($spSite,$spTemplate,$spListName,$spDescription){
$spSite=Get-SPSite $spSite
$spWeb=$spSite.RootWeb
try{
# Get all the custom template
$listTemplates = $spSite.GetCustomListTemplates($spWeb);
# Create the list via the template name
$spWeb.Lists.Add($spListName, $spDescription, $listTemplates[$spTemplate])
$list=$spWeb.Lists[$spListName]
# Make the list view in OnQuickLaunch
$list.OnQuickLaunch="True"
$list.Update()
}
catch{
write-host "(ERROR : "$_.Exception.Message")"
throw
}
finally{
if($spWeb -eq $null){
write-host "The web site is not existing"
}
else{
$spWeb.Dispose()
}
}
}
# Add the view of column that you want to view
# Example: AddColumnView "http://localhost" "http://localhost/Lists/MyNewList/AllItems.aspx" "MyNewList" "Address"
function AddColumnView($spWeb,$spView,$spList,$columnName){
$spWeb=Get-SPWeb -Identity $spWeb
try{
$spList=$spWeb.Lists[$spList]
# Get the view list by the url
$spView=$spWeb.GetViewFromUrl($spView)
# Get the field by column name ,then add it
$spField=$spList.Fields[$columnName]
$spView.ViewFields.Add($spField)
$spView.Update()
}
catch{
write-host "(ERROR : "$_.Exception.Message")"
throw
}
finally{
if($spWeb -eq $null){
write-host "The web site is not existing"
}
else{
$spWeb.Dispose()
}
}
}
# Delete column view
# Example : AddColumnView "http://localhost" "http://localhost/Lists/MyNewList/AllItems.aspx" "MyNewList" "Address"
function AddColumnView($spWeb,$spView,$spList,$columnName){
$spWeb=Get-SPWeb -Identity $spWeb
try{
$spList=$spWeb.Lists[$spList]
# Get the View if the list by the view url
$spView=$spWeb.GetViewFromUrl($spView)
# Get the field should be deleted
$spField=$spList.Fields[$columnName]
$spView.ViewFields.Delete($spField)
$spView.Update()
}
catch{
write-host "(ERROR : "$_.Exception.Message")"
throw
}
finally{
if($spWeb -eq $null){
write-host "The web site is not existing"
}
else{
$spWeb.Dispose()
}
}
}
# Delete the item by the Title
# Example : DeleteItemByTitle "http://localhost" "MyNewList" "007"
function DeleteItemByTitle($spWeb,$spList,$spTitle){
$spWeb=Get-SPWeb -Identity $spWeb
try{
$spList=$spWeb.Lists[$spList]
# Initial the query object
$spQuery=New-Object Microsoft.SharePoint.SPQuery
# Query the item via CAML
$camlQuery='<Where><Eq><FieldRef Name="Title"/><Value Type="Text">$spTitle</Value></Eq></Where>'
$spQuery.Query=$camlQuery
$spQuery.RowLimit=100
# Execute the CAML query statement
$spListItem=$spList.GetItems($spQuery)
# Find the right item in circle
$spListItem|ForEach-Object {
$_.Delete()
}
}
catch{
write-host "(ERROR : "$_.Exception.Message")"
throw
}
finally{
if($spWeb -eq $null){
write-host "The web site is not existing"
}
else{
$spWeb.Dispose()
}
}
}
# Delete Column with its title
# Example : DeleteColumn "http://localhost" "MyNewList" "Address"
function DeleteColumn($spWeb,$spListName,$title){
$spWeb=Get-SPWeb -Identity $spWeb
try{
$spList=$spWeb.Lists[$spListName]
$column=$spList.Fields[$title]
# Show the column and make the column be read, the operate
$column.Hidden=$false
$column.ReadOnlyField=$false
$column.Update()
$spList.Fields.Delete($column)
}
catch{
write-host "(ERROR : "$_.Exception.Message")"
throw
}
finally{
if($spWeb -eq $null){
write-host "The web site is not existing"
}
else{
$spWeb.Dispose()
}
}
}
# Download the file by the link
# Example : DownLoadFile "http://localhost/DocumentUpload/1.txt " "C:\Users\v-trdong\Desktop\ListTemplate\1.txt"
function DownLoadFile($source,$destination){
try{
# The source url you want to download
$source = $source
# The destination path in disk you want to put
$destination = $destination
$wc = New-Object System.Net.WebClient
# Call the function to download
$wc.DownloadFile($source, $destination)
}
catch{
write-host "(ERROR : "$_.Exception.Message")"
throw
}
finally{
write-host "DownLoad success!"
}
}
分享到:
相关推荐
Setting SharePoint list item validation with PowerShell 78 Setting list item security 84 ii Table of Contents Setting list relationships 89 Customizing list views 94 Managing the use of content types ...
PowerShell_for_SharePoint_2010
The final guide to SharePoint 2010 Site Settings by PowerShell
附加SharePoint PowerShell模块,利用SharePoint PnP PowerShell模块以递归方式将文件和文件夹下载到SharePoint或从SharePoint上载。 如何安装模块 发布在,可以使用PowerShell 5.x或更高版本通过Install-Module ...
PowerShell for Microsoft SharePoint 2010 Administrators.pdf
该解决方案包含一个PowerShell命令库,该命令库使您可以对SharePoint执行复杂的配置和工件管理操作。 这些命令在后台使用CSOM和REST的组合,并且可以与SharePoint Online一起作为SharePoint内部部署。 我发现了一个...
you'll discover how to plan, design, deploy, and manage strategic solutions using SharePoint 2010, Microsoft SQL Server®, Windows PowerShell™, and other key technologies. Topics include ...
前言:某一天发现一个powershell脚本,进行了尝试可发现可进行免杀,但是对其中的混淆方法始终不理解,于是通过谷歌发现了具体方法,发现该文章写的还是很不错的
1 Key Deploy SharePoint Solutions
Exchange 2010 PowerShell Cheat Sheet,介绍了Exchange 2010的命令及功能。
McGraw-Hill.PowerShell.for.Microsoft.SharePoint.2010.Administrators
Microsoft Exchange 2010 PowerShell Cookbook
Base64混淆器简单的PowerShell Base64编码器,可避免检测到恶意负载用法除@danielhbohannon系统外,其他任何地方都应该工作,因为他的Get-Random返回任意值。 \ o / PS> import-module .\Obfuscator.ps1; Base64-...
PowerShell脚本,该脚本允许获取SharePoint 2010的所有URL的大小
与Microsoft SharePoint 2010的OData API的PowerShell接口 动机 我想要一种使用PowerShell与SharePoint 2010进行交互的方法。 我无法使用SharePoint 2010命令行管理程序。 一些研究使我找到了SharePoints OData ...
从印度小哥那里受到启发,PowerShell不止可以做批处理,自动化。还能做界面做GUI,也能实现很好的交互。因为PowerShell是可以和.Net 程序无缝集成的。所以.Net能用的东西在PowerShell里也几乎都能使用。那么如果想让...
1 Introducing Microsoft SharePoint 2010 . 3 What Is SharePoint? 3 Main Capabilities 4 Sites . 5 Communities 5 Content . 5 Search . 6 Insights 6 Composites 6 SharePoint Basic Concepts 7 SharePoint ...
适合学习PowerShell的资料,详细介绍了PowerShell的使用方法!
powershell脚本转exe文件powershell脚本转exe文件powershell脚本转exe文件powershell脚本转exe文件