Home > Mobile >  The term 'Get-SPOList' is not recognized as the name of a cmdlet, function, script file, o
The term 'Get-SPOList' is not recognized as the name of a cmdlet, function, script file, o

Time:01-16

I have this script and when I execute it, I get the below error.

The term 'Get-SPOList' is not recognized as the name of a cmdlet, function, script file, or operable program.Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

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 }

The script copies items from a Source List to Destination List.

However this error happens that the cmdlet is not recognized.

I tried installing the SharePoint Powershell Module and PnP SharePoint Online Powershell Module but I am still getting the same error.

CodePudding user response:

Firstly, the cmdlet Get-SPOList does not exists on any of the PS modules. This can be easily seen by going over to powershellgallery results

You might have missed a step or two of the tutorial in order to copy list items from one list to another.

Secondly, the Microsoft.Online.SharePoint.PowerShell Module is mostly needed to perform Administration-oriented tasks on the SPO and the tenant behind it. You will not be able to find cmdlets that will help you with your task from this PS Module.

Lastly, a simple copy-paste script for the list items of a source list to a destination list could be the below, taken from SharePointDiary's blog, which by the way, you can read through in order to help you with your task:

        #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  
        }

CodePudding user response:

get-SPOList is part of the Microsoft.Online.SharePoint.PowerShell powershell module available in the PowerShell Gallery. To install:

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

To install for current user only (when you do not have admin privileges):

Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser
  • Related