1

I have a folder in SharePoint online that the name starts with character # for example #23 - 05 and my script does get all items from all site except the items that there inside of that folder.

Do you know why is this happenning?

This is the part of the code where I get the issue

function Get-SPORootSite{ Param( [Microsoft.SharePoint.Client.ClientContext]$Context, [Microsoft.SharePoint.Client.Web]$RootWeb)

        #Create array variable to store data
        $siteitems = $null
        $siteitems = @()
            Write-Host $RootWeb.url
            $Context.Load($RootWeb)
            $Context.ExecuteQuery()
            $siteUrl = $RootWeb.Url;
            $web = $Context.Web
            $Context.Load($web)
            $Context.ExecuteQuery()
            $AllLists = $Context.Web.Lists
            $Context.Load($AllLists)
            $Context.ExecuteQuery()
            ForEach ($list in $AllLists){
             $listTitle = $list.Title;
              If($list.BaseType.ToString() -eq "DocumentLibrary" -and $listTitle -ne 'User Information List' -and `
                 $listTitle -ne 'Workflow History' -and `
                 $listTitle -ne 'ATIConfiguration' -and `
                 $listTitle -ne 'Site Pages' -and `
                 $listTitle -ne 'wfsvc' -and `
                 $listTitle -ne 'Images' -and `
                 $listTitle -ne 'Site Assets' -and `
                 $listTitle -ne 'Composed Looks' -and `
                 $listTitle -ne 'appfiles' -and `
                 $listTitle -ne 'Form Templates' -and `
                 $listTitle -ne 'Microfeed' -and `
                 $listTitle -ne 'Search Config List' -and `
                 $listTitle -ne 'Theme Gallery' -and `
                 $listTitle -ne 'Form Templates ' -and `
                 $listTitle -ne 'wfpub' -and `
                 $listTitle -ne 'Maintenance Log Library' -and `
                 $listTitle -ne 'Converted Forms' -and `
                 $listTitle -ne 'Solution Gallery' -and `
                 $listTitle -ne 'Workflow Tasks' -and `
                 $listTitle -ne 'Access Requests' -and `
                 $listTitle -ne 'Master Page Gallery' -and  `
                 $listTitle -ne 'Web Part Gallery' -and `
                 $listTitle -ne 'Style Library' -and `                 
                 $listTitle -ne 'List Template Gallery') {

                 #Create a CAML Query object
                 $query = New-Object Microsoft.SharePoint.Client.CamlQuery
                 $query.ViewXml = " <View Scope='RecursiveAll'><ViewFields><FieldRef Name='FileDirRef' /><FieldRef Name='ItemChildCount' /><FieldRef Name='Disclosed' /><FieldRef Name='Disclosure_x0020_Activity' /><FieldRef Name='UniqueId' /><FieldRef Name='UniqueId' /><FieldRef Name='GUID' /><FieldRef Name='File_x0020_Type' /><FieldRef Name='ID' /><FieldRef Name='Access_x0020_to_x0020_Information_x00A0_Policy' /><FieldRef Name='Function_x0020_Corporate_x0020_IDB' /><FieldRef Name='Series_x0020_Corporate_x0020_IDB' /><FieldRef Name='Division_x0020_or_x0020_Unit' /><FieldRef Name='Country' /><FieldRef Name='Created' /><FieldRef Name='Modified' /><FieldRef Name='CheckoutUser' /><FieldRef Name='Author' /><FieldRef Name='Editor' /><FieldRef Name='SISCOR_x0020_Number' /><FieldRef Name='_dlc_DocIdUrl' /><FieldRef Name='_dlc_DocId' /><FieldRef Name='Title' /><FieldRef Name='FileRef' /></ViewFields><RowLimit>100</RowLimit> </View>"               
                 do
                   {
                     $listItems = $list.getItems($query)
                     $Context.Load($listItems)
                     $Context.ExecuteQuery()
                     $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition   

                     foreach($item in $listItems)
                        {
                         Try
                            {
                                 $GUID = $item["GUID"]
                                 $listUrl = $item["FileDirRef"]
                                 $itemTitle = $item["FileLeafRef"]                               
                                 #retrieve item values
                                 $itemType = $item.FileSystemObjectType
                                 $itemurl = $item["FileRef"]
                                 $itemCreatedBy = $item["Author"].LookupValue
                                 $itemCreated = $item["Created"]
                                 $itemModifiedBy = $item["Editor"].LookupValue
                                 $itemModified = $item["Modified"]
                                 $itemdocID = $item["_dlc_DocId"]
                                 $itemFunction =$item["Function_x0020_Corporate_x0020_IDB"].Label
                                 $itemSeries=$item["Series_x0020_Corporate_x0020_IDB"].Label
                                 $itemSISCOR =$item["SISCOR_x0020_Number"]
                                 $itemAccessPolicy=$item["Access_x0020_to_x0020_Information_x00A0_Policy"]
                                 $itemCountry=$item["Country"].Label
                                 $itemDivision=$item["Division_x0020_or_x0020_Unit"]                                                   
                                 $itemFiletype=$item["File_x0020_Type"]
                                 $itemDocID=$item["_dlc_DocId"] 
                                 $itemDislosed =$item["Disclosed"]
                                 $itemDisclosureActivity =$item["Disclosure_x0020_Activity"]
                                 $LibraryCount = $list.ItemCount;
                                 $temp=0;
                                  ."C:\SPOnline\Scripts\Load-CSOMProperties.ps1" 
                                 Load-CSOMProperties -object $item -propertyNames @("HasUniqueRoleAssignments");
                                 $Context.ExecuteQuery()
                                 ### Get Only Documents with Broken Inheritance 

                                if($item.HasUniqueRoleAssignments -eq $true)                                                             
                                { 
                                  Write-Host Item Name: $itemTitle ,$itemdocID ,$listurl -BackgroundColor Yellow
                                 #### Get File Checkedout Details #############       
                                 if($itemType -ne 'Folder')
                                   {                         
                                     $file = $Context.Web.GetFileByServerRelativeUrl($item["FileRef"]);
                                     $Context.Load($file)    
                                     $Context.ExecuteQuery()
                                     $CheckedOutByUser=$file.CheckedOutByUser  
                                     $Context.Load($CheckedOutByUser)  
                                     $Context.ExecuteQuery()
                                     if($CheckedOutByUser.LoginName -ne $null)
                                       { 
                                          Write-Host "CheckedOutBy:" $CheckedOutByUser.LoginName -BackgroundColor Red                                
                                          $checkedoutfile ="Yes"
                                          $checkedoutby =$CheckedOutByUser.LoginName;
                                       }
                                     else
                                       {
                                           $checkedoutfile =""
                                           $checkedoutby =""
                                       }
                                   }
                                   else
                                       {
                                           $checkedoutfile =""
                                           $checkedoutby =""
                                       }                                   
                                   $props = [ordered]@{ 'UniqueId'=$GUID;
                                   'Path' = $itemUrl;
                                   'SiteURL' = $siteUrl;
                                   'LibURL'=$listUrl;                                    
                                   'Item Type' = $itemType;   
                                   'Item Count' = $LibraryCount;
                                   'Lib Name' = $listTitle;
                                   'Title' = $itemTitle;      
                                   'FileType' =$itemFiletype;  
                                   'Modified' = $itemModified ;                               
                                   'ModifiedBy' = $itemModifiedBy;
                                   'Created' = $itemCreated;
                                   'CreatedBy' = $itemCreatedBy;
                                   'Checked Out' =$checkedoutfile ;
                                   'Checked Out To' =$checkedoutby ;
                                   'Org Unit' =$itemDivision;
                                   'Country' =$itemCountry;
                                   'FunctionCorp' =$itemFunction;
                                   'Series' =$itemSeries;
                                   'Access Policy' =$itemAccessPolicy;
                                   'Disclosed'=$itemDislosed;
                                   'Disclosure Activity'=$itemDisclosureActivity;                                                                
                                   'DOCNumber' =$itemdocID;                                                            
                                   'SISCOR Number' =$itemSISCOR;
                                   'Permissions Inheritance Broken' ="Yes"    
                               };
                                 #append the values to the existing array object 
                                 $siteitemarray = New-Object -TypeName PSObject -Property $props; $siteitems += $siteitemarray
                               }
                               else{

                                 if($itemType -ne 'Folder')
                                {

                                 $file = $Context.Web.GetFileByServerRelativeUrl($item["FileRef"]);
                                 $Context.Load($file)                                                                         
                                 $Context.ExecuteQuery()                                    
                                 $CheckedOutByUser=$file.CheckedOutByUser  
                                 $Context.Load($CheckedOutByUser)  
                                 $Context.ExecuteQuery()
                                   if($CheckedOutByUser.LoginName -ne $null)
                                   {
                                      Write-Host "CheckedOutBy:" $CheckedOutByUser.LoginName -BackgroundColor Red                                
                                      $checkedoutfile ="Yes"
                                      $checkedoutby =$CheckedOutByUser.LoginName;
                                   }
                                   else
                                   {
                                       $checkedoutfile =""
                                       $checkedoutby =""
                                   }
                               }
                                   $props = [ordered]@{ 'UniqueId'=$GUID;
                                   'Path' = $itemUrl;
                                   'SiteURL' = $siteUrl;
                                   'LibURL'=$listUrl;                                    
                                   'Item Type' = $itemType;   
                                   'Item Count' = $LibraryCount;
                                   'Lib Name' = $listTitle;
                                   'Title' = $itemTitle;      
                                   'FileType' =$itemFiletype;  
                                   'Modified' = $itemModified ;                               
                                   'ModifiedBy' = $itemModifiedBy;
                                   'Created' = $itemCreated;
                                   'CreatedBy' = $itemCreatedBy;
                                   'Checked Out' =$checkedoutfile ;
                                   'Checked Out To' =$checkedoutby ;
                                   'Org Unit' =$itemDivision;
                                   'Country' =$itemCountry;
                                   'FunctionCorp' =$itemFunction;
                                   'Series' =$itemSeries;
                                   'Access Policy' =$itemAccessPolicy;
                                   'Disclosed'=$itemDislosed;
                                   'Disclosure Activity'=$itemDisclosureActivity;                                                                
                                   'DOCNumber' =$itemdocID;                                                            
                                   'SISCOR Number' =$itemSISCOR;
                                   'Permissions Inheritance Broken' ="No"   
                                };
                                 #append the values to the existing array object 
                                 $siteitemarray = New-Object -TypeName PSObject -Property $props; 
                                 $siteitems += $siteitemarray    
                               }
                             }
                         Catch [System.Exception]
                             {
                                   Write-Host $_.Exception.Message
                             }
                         }
                     } While($query.ListItemCollectionPosition -ne $null)
                   } #check if it is a 'do not inventory' list          
                 } #end loop for all lists in site 
                 #Get-SPOSites -RootWeb $sWeb -Context $Context #recursive call          
                #end loop for all sites in site collection     
           #Output site collection inventory to CSV 
           $siteitems | Export-Csv $OutputFile -Append -Encoding UTF8 -NoTypeInformation
           }

Thanks in advance

  • can you share the code snippet of the script that you are using ? – Gautam Sheth Apr 5 '19 at 4:47
  • Hello Seth I already post a little bit of the code I am using – Pedro Guevara Apr 8 '19 at 11:41
1

See if it helps you Reference:https://support.office.com/en-us/article/Invalid-file-names-and-file-types-in-OneDrive-OneDrive-for-Business-and-SharePoint-64883a5d-228e-48f5-b3d2-eb39e07630fa enter image description here

| improve this answer | |
  • Please accept as solution if it clears your query – Sayyed Amir Hussain Apr 5 '19 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.