【发布时间】:2013-12-12 18:56:47
【问题描述】:
我想将同一文件上传到所有网站集中具有相同层次结构的多个网站集。我想使用 PowerShell 并包含自动签入/签出功能。
我已经能够在 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)};
通过此代码,文件已上传但已检出。我希望它自动签入。如果文件在那里,则首先自动签出然后签入。
【问题讨论】:
-
我不会把这个作为答案,因为我只是从另一个帖子中复制。这可能会让你上路,consultingblogs.emc.com/robertoortega/archive/2012/03/03/…
-
谢谢 Ola,我已经检查了这段代码,但我无法理解,我应该如何一起使用这两个代码。上传代码后调用此代码不起作用。谢谢
-
您可以在尝试运行时发布输出吗?
-
窗口突然消失。我正在使用上面的代码,它只上传文件,但不适用于签入/签出。那么我们可以使用任何函数来获得它。 !!非常感谢您的支持
-
您能否编辑您的原始问题并复制并粘贴您正在运行的脚本,就像它在 .ps1 文件中一样。
标签: sharepoint powershell sharepoint-2010 powershell-2.0 powershell-3.0