SharePoint PowerShell Script Create Document Library,Upload File

//创建文档库

$web = get-spweb -Identity http://dexter-pc:90;

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary;

$web.Lists.Add("Document Name","Document Desc",$listTemplate);

//得到文档库

$spDocumentLibrary = $web.GetList("Document Name");

//更该文档库的Description

$spDocumentLibrary.Description = "My Description";

//设置文档库是否在快速导航上显示

$spDocumentLibrary.OnQuickLaunch = "True";

//更新

$spDocumentLibrary.Update();

 

//在文档库中添加文件夹

$spFolder = $spDocumentLibrary.AddItem("",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,"New Folder");

$spFolder.Update();

 

//上传一个文件到文档库

$spFolder = $web.GetFolder("My Documents");

$spFileCollection = $spFolder.Files;

$spFile = Get-ChildItem C:\Documents\Doc.docx;

$spFileCollection.Add("My Documents/Doc.Docx",$spFile.OpenRead(),$false);

 

//上传多个文件

Get-ChildItem C:\Documents -filter "*.docx"|ForEach{$spFileCollection.Add("My Documents/$($_.Name)",$_.OpenRead(),$true) };

 

 

posted on 2011-01-17 22:41  张大明  阅读(688)  评论(0编辑  收藏  举报

导航