SharePoint PowerShell Script Create Document Library,Upload File
时间:2011-01-17 来源:张大明
$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) };