适用于 SharePoint 的 Powershell>>出现我们!rd 错误

发布于 2024-12-01 21:51:18 字数 1501 浏览 0 评论 0原文

我在这段代码上不断收到以下错误:

#Setup default variables
$webUrl = Get-SPWeb -Identity "http://CiscoIntranet/sites/VOIP"
$list = $webUrl.GetList("http://CiscoIntranet/sites/VOIP/ForwardTech")
[System.Reflection.Assembly]::LoadWithPartialName(”Microsoft.SharePoint”) 

function ProcessMove {
   param($folderUrl)
   $folder = $web.GetFolder($folderUrl)
        foreach ($file in $folder.Files)
            {
                [Microsoft.SharePoint.SPFile]$spFile = $file;           
                $docset=$($file.Counterparty2);
                $destinationFolderUrl = "http://CiscoIntranet/sites/VOIP/ForwardTech/" + $docset;               
                $spFile.MoveTo($destinationFolderUrl + $file.Name, $true);
                $webUrl.Update();
            }
}
#Move root Files
ProcessMove($list.RootFolder.Url)

You cannot call a method on a null-valued expression.
At C:\PS\MoveFiles.ps1:8 char:28
+    $folder = $web.GetFolder <<<< ($folderUrl)
    + CategoryInfo          : InvalidOperation: (GetFolder:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Method invocation failed because [Microsoft.SharePoint.SPListItemCollection] doesn't contain a method named 'MoveTo'.
At C:\PS\MoveFiles.ps1:13 char:23
+                 $list.Items.MoveTo <<<< ($destinationFolderUrl + $file.Name, $true);
    + CategoryInfo          : InvalidOperation: (MoveTo:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

I keep getting following error on this code:

#Setup default variables
$webUrl = Get-SPWeb -Identity "http://CiscoIntranet/sites/VOIP"
$list = $webUrl.GetList("http://CiscoIntranet/sites/VOIP/ForwardTech")
[System.Reflection.Assembly]::LoadWithPartialName(”Microsoft.SharePoint”) 

function ProcessMove {
   param($folderUrl)
   $folder = $web.GetFolder($folderUrl)
        foreach ($file in $folder.Files)
            {
                [Microsoft.SharePoint.SPFile]$spFile = $file;           
                $docset=$($file.Counterparty2);
                $destinationFolderUrl = "http://CiscoIntranet/sites/VOIP/ForwardTech/" + $docset;               
                $spFile.MoveTo($destinationFolderUrl + $file.Name, $true);
                $webUrl.Update();
            }
}
#Move root Files
ProcessMove($list.RootFolder.Url)

You cannot call a method on a null-valued expression.
At C:\PS\MoveFiles.ps1:8 char:28
+    $folder = $web.GetFolder <<<< ($folderUrl)
    + CategoryInfo          : InvalidOperation: (GetFolder:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Method invocation failed because [Microsoft.SharePoint.SPListItemCollection] doesn't contain a method named 'MoveTo'.
At C:\PS\MoveFiles.ps1:13 char:23
+                 $list.Items.MoveTo <<<< ($destinationFolderUrl + $file.Name, $true);
    + CategoryInfo          : InvalidOperation: (MoveTo:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缪败 2024-12-08 21:51:18

这是工作代码...

$siteURL="http://CiscoIntranet/sites/VOIP"
$docLib = "ForwardTech"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$collFiles=$web.GetFolder($docLib).Files
$count=$collFiles.Count
while($count -ne 0)
{
$item = $collFiles[$count-1].Item
$DocSet = $item["Region"]
Write-Host "$DocSet is the doc set. $collFiles[$count-1].Name is name"
$collFiles[$count-1].MoveTo($siteURL + "/" + $docLib + "/" + $DocSet + "/"  + $collFiles[$count-1].Name, $true)                       
$count--
}

This is the working code...

$siteURL="http://CiscoIntranet/sites/VOIP"
$docLib = "ForwardTech"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$collFiles=$web.GetFolder($docLib).Files
$count=$collFiles.Count
while($count -ne 0)
{
$item = $collFiles[$count-1].Item
$DocSet = $item["Region"]
Write-Host "$DocSet is the doc set. $collFiles[$count-1].Name is name"
$collFiles[$count-1].MoveTo($siteURL + "/" + $docLib + "/" + $DocSet + "/"  + $collFiles[$count-1].Name, $true)                       
$count--
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文