sharepoint - 使用 powershell 将文件上传到 SharePoint 文档库

标签 sharepoint powershell sharepoint-2010 powershell-2.0 powershell-3.0

我想将同一文件上传到所有网站集中具有相同层次结构的多个网站集。我想使用 PowerShell 并包含自动 checkin / checkout 功能。

我已经能够在 SharePoint 中上传文件。下面是代码。 :

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

# create the Variable Path and Pass the source folder path
$path = “D:\ABC\DEF\26Nov\”;

# create the Variable destination and pass the URL of the SharePoint List
$destination = "complete URL of File will be mentioned here";

# Store the current user default credentials in the Variable Credentials
$credentials = [System.Net.CredentialCache]::DefaultCredentials;

# Create the object of the Webclient
$webclient = New-Object System.Net.WebClient;

# Pass the user credentials
$webclient.Credentials = $credentials; Get-ChildItem

# “For Each” loop will upload all of the files one by one onto the destination using the UploadFile method
Get-ChildItem $path | ForEach-Object { $webclient.UploadFile($destination + “/” + $_.Name, “PUT”, $_.FullName)};

通过此代码,文件已上传但已 checkout 。我希望它自动 checkin 。如果文件在那里,则首先自动 checkout ,然后 checkin 。

最佳答案

这是外行风格的简单脚本,经过测试并且可以正常工作,可以将文件从驱动器上传到 SharePoint 文档库

http://soreddymanjunath.blogspot.in/2014/07/add-file-to-document-library-using.html

cls

asnp "*sh*"

$url=Read-Host "Enter Site Url" 

$web=Get-SPWeb -Identity $url

if($web)
{
try
{
$list = $web.Lists.TryGetList("Documents")

$files = Get-ChildItem -Path "D:\Manju" -Force -Recurse

    foreach ($file in $files)
    {
      $stream = $file.OpenRead()

      $done= $list.RootFolder.Files.Add($file.Name, $stream, $true)

      Write-Host $done.Name  "Uploaded into the Site" -BackgroundColor Green         

    }
}
catch
{
$ErrorMessage = $_.Exception.Message
Write-Host $ErrorMessage
}
}

else
{
Write-Host "Site Doesn't exist"
}

$list.Update();

关于sharepoint - 使用 powershell 将文件上传到 SharePoint 文档库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20237294/

相关文章:

powershell - 在 VBS 中使用参数调用 Powershell

.net - 持久共享点 EditorPart 设置

c# - 在 SharePoint 2010 中,如何在运行时添加用户选择的 WebPart?

sharepoint - 人员选择器能否解析 FBA 扩展网站中的 NTLM 用户

python-3.x - Discord.py 在 Windows 10 上安装失败(Python 3.9,包括日志)

xml - 用于更新 Sharepoint 列表的 SAS PROC SOAP

powershell - Sitecore Powershell get-user命令

javascript - 在 SharePoint2010 Client OM/ECMAScript 中获取当前用户

c# - Word 加载项 : Getting user credentials which were used to open the document from SharePoint

macos - macOS PowerShell Connect-PnPOnline是否由于advapi32.dll而失败?