我有这个脚本,当我执行它时,出现以下错误。
术语“Get-SPOList”不被识别为 cmdlet 的名称, 函数、脚本文件或可运行程序。检查拼写 名称,或者如果包含路径,请验证路径是否正确并且 再试一次。
Connect-SPOService -Url https://xxxxxxxxxxx
$web = Get-SPOWeb
Get the source list
$sourceList = Get-SPOList -Identity xxx
Get the destination list
$destinationList = Get-SPOList -Identity xxxx
Get all items with a "Closed" status from the source list
$items = Get-SPOListItem -List $sourceList | Where-Object {$_["Status"] -eq "Closed"}
Add each item to the destination list
foreach ($item in $items) { Add-SPOListItem -List $destinationList -Values $item.FieldValues
Remove the item from the source list
Remove-SPOListItem -Identity $item -Force }
该脚本将项目从源列表复制到目标列表。
但是会发生此错误,因为无法识别 cmdlet。
我尝试安装
SharePoint Powershell Module
和 PnP SharePoint Online Powershell Module
但我仍然遇到相同的错误。
首先,cmdlet
Get-SPOList
不存在于任何 PS 模块上。
通过转到 Powershell Gallery 并查询下面的 Cmdlets:"Get-SPOList"
可以轻松看到这一点,将为您提供 0 个结果。
为了将列表项从一个列表复制到另一个列表,您可能错过了本教程的一两个步骤。
其次,
Microsoft.Online.SharePoint.PowerShell Module
主要用于对 SPO 及其背后的租户执行面向管理的任务。您将无法在此 PS 模块中找到可帮助您完成任务的 cmdlet。
最后,下面是一个将源列表的列表项复制粘贴到目标列表的脚本,取自 SharePointDiary 的博客,顺便说一下,您可以通读该脚本以帮助您完成任务:
#Get All Items from the Source List in batches
Write-Progress -Activity "Reading Source..." -Status "Getting Items from Source List. Please wait..."
$SourceListItems = Get-PnPListItem -List $SourceListName -PageSize 500
$SourceListItemsCount= $SourceListItems.count
Write-host "Total Number of Items Found:"$SourceListItemsCount
#Get fields to Update from the Source List - Skip Read only, hidden fields, content type and attachments
$SourceListFields = Get-PnPField -List $SourceListName | Where { (-Not ($_.ReadOnlyField)) -and (-Not ($_.Hidden)) -and ($_.InternalName -ne "ContentType") -and ($_.InternalName -ne "Attachments") }
#Loop through each item in the source and Get column values, add them to target
[int]$Counter = 1
ForEach($SourceItem in $SourceListItems)
{
$ItemValue = @{}
#Map each field from source list to target list
Foreach($SourceField in $SourceListFields)
{
#Check if the Field value is not Null
If($SourceItem[$SourceField.InternalName] -ne $Null)
{
#Handle Special Fields
$FieldType = $SourceField.TypeAsString
If($FieldType -eq "User" -or $FieldType -eq "UserMulti" -or $FieldType -eq "Lookup" -or $FieldType -eq "LookupMulti") #People Picker or Lookup Field
{
$LookupIDs = $SourceItem[$SourceField.InternalName] | ForEach-Object { $_.LookupID.ToString()}
$ItemValue.add($SourceField.InternalName,$LookupIDs)
}
ElseIf($FieldType -eq "URL") #Hyperlink
{
$URL = $SourceItem[$SourceField.InternalName].URL
$Description = $SourceItem[$SourceField.InternalName].Description
$ItemValue.add($SourceField.InternalName,"$URL, $Description")
}
ElseIf($FieldType -eq "TaxonomyFieldType" -or $FieldType -eq "TaxonomyFieldTypeMulti") #MMS
{
$TermGUIDs = $SourceItem[$SourceField.InternalName] | ForEach-Object { $_.TermGuid.ToString()}
$ItemValue.add($SourceField.InternalName,$TermGUIDs)
}
Else
{
#Get Source Field Value and add to Hashtable
$ItemValue.add($SourceField.InternalName,$SourceItem[$SourceField.InternalName])
}
}
}
Write-Progress -Activity "Copying List Items:" -Status "Copying Item ID '$($SourceItem.Id)' from Source List ($($Counter) of $($SourceListItemsCount))" -PercentComplete (($Counter / $SourceListItemsCount) * 100)
#Copy column value from source to target
$NewItem = Add-PnPListItem -List $TargetListName -Values $ItemValue
Write-Host "Copied Item ID from Source to Target List:$($SourceItem.Id) ($($Counter) of $($SourceListItemsCount))"
$Counter++
}
get-SPOList
是 PowerShell 库中提供的 Microsoft.Online.SharePoint.PowerShell powershell 模块的一部分。安装:
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
仅为当前用户安装(当您没有管理员权限时):
Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser
多么糟糕的答案,它甚至不起作用,你在建议之前尝试过吗?