Need to convert System Object value to Array value

I am writing script, where i have requirement to fetch the data as systemObject which has 20 Plus parameter and values, However i need to convert this to array so that i am able to compare it with another object.


$flag = @()

$RLD_SPOT = get-spotenant


if(($RLD_SPOT[$i]) -ne ($curentTenantValue[$i]))

$Flag += $currentTenantValue[i]


Even though I have tried to convert this as Array, whole result stored in $rlds_spot[o]
I am seeking your suggestion to convert this object by breaking each line and store it in array to process later

line 12 should read [$i] at the end

Here’s an example that may help:

This line provides an array of objects:
(System.IO.FileInfo in this case but example applies to any object)

Get-ChildItem .\ -File | select -First 10 

To go through that array and execute a command or a script block against each element I can do something like:

Get-ChildItem .\ -File | select -First 10 | foreach {
    if ($PSItem.Name -match 'ad') { $PSItem.FullName }

This will give me the files that have ‘ad’ in the name. Specifically the file’s full name.
Note that to get the output you simple dump it in the pipeline as in the script block { $PSItem.FullName }
To retain that output in a variable, I can do:

$myOutput = Get-ChildItem .\ -File | select -First 10 | foreach {
    if ($PSItem.Name -match 'ad') { $PSItem.FullName }

The script block { $PSItem.FullName } can be further developed to produce a more useful output as in:

$myOutput = Get-ChildItem .\ -File | select -First 10 | foreach {
    if ($PSItem.Name -match 'ad') { 
            ComputerName = $env:COMPUTERNAME
            FileName = $PSItem.FullName 

In this case the output is an array of objects, where each element has a ‘ComputerName’ and ‘FileName’ properties:

ComputerName FileName                                               
------------ --------                                               
SAM2017E     \\\e$\Install\Scripts\AD DS Deployment (2).txt
SAM2017E     \\\e$\Install\Scripts\AD DS Deployment.txt    
SAM2017E     \\\e$\Install\Scripts\AD-Bla1.ps1             
SAM2017E     \\\e$\Install\Scripts\AD-Deployment.txt       
SAM2017E     \\\e$\Install\Scripts\AD-PasswordExpired.ps1  
SAM2017E     \\\e$\Install\Scripts\AD1.ps1 

When i tried to read the value from Object it shows as count “1” but actually it has list of values, which i couldn’t differentiate or split to store in the array, that is the main problem i am facing

$RLD_SPOT = get-spotenant


$jsonIfile = Get-content -Raw "C:\Scripts\SPOTenant.json"
$curentTenantValue = ConvertFrom-Json -InputObject $jsonIfile 

what’s the output of

$RLD_SPOT | gm

Assuming $curentTenantValue and $RLD_SPOT are type ‘string’

$RLD_SPOT = get-spotenant
$flag = 0..($RLD_SPOT.Length-1) | foreach {
    if($RLD_SPOT.Chars($PSItem) -ne $curentTenantValue.Chars($PSItem)) {
$flag = $flag -join ''

A string is not treated here as an array of characters that you can address as $VariableName[int] for example. However, the string type has a .chars(int) parameterized property that gives you essentially the same functionality…


$String = 'myString'

$ArrayofChars = 0..($String.Length-1) | foreach { $String.Chars($PSItem) }

$BacktoString = $ArrayofChars -join ''

Thanks Sam, here is the get-members list

Name                                       MemberType Definition                                                                                                         
----                                       ---------- ----------                                                                                                         
Equals                                     Method     bool Equals(System.Object obj)                                                                                     
GetHashCode                                Method     int GetHashCode()                                                                                                  
GetType                                    Method     type GetType()                                                                                                     
ToString                                   Method     string ToString()                                                                                                  
BccExternalSharingInvitations              Property   bool BccExternalSharingInvitations {get;}                                                                          
BccExternalSharingInvitationsList          Property   string BccExternalSharingInvitationsList {get;}                                                                    
CompatibilityRange                         Property   string CompatibilityRange {get;}                                                                                   
DefaultSharingLinkType                     Property   Microsoft.Online.SharePoint.TenantManagement.SharingLinkType DefaultSharingLinkType {get;}                         
DisallowInfectedFileDownload               Property   bool DisallowInfectedFileDownload {get;}                                                                           
DisplayStartASiteOption                    Property   bool DisplayStartASiteOption {get;}                                                                                
EnableGuestSignInAcceleration              Property   bool EnableGuestSignInAcceleration {get;}                                                                          
ExternalServicesEnabled                    Property   bool ExternalServicesEnabled {get;}                                                                                
FileAnonymousLinkType                      Property   Microsoft.SharePoint.Client.AnonymousLinkType FileAnonymousLinkType {get;}                                         
FolderAnonymousLinkType                    Property   Microsoft.SharePoint.Client.AnonymousLinkType FolderAnonymousLinkType {get;}                                       
IPAddressAllowList                         Property   string IPAddressAllowList {get;}                                                                                   
IPAddressEnforcement                       Property   bool IPAddressEnforcement {get;}                                                                                   
IPAddressWACTokenLifetime                  Property   int IPAddressWACTokenLifetime {get;}                                                                               
LegacyAuthProtocolsEnabled                 Property   bool LegacyAuthProtocolsEnabled {get;}                                                                             
NoAccessRedirectUrl                        Property   string NoAccessRedirectUrl {get;}                                                                                  
NotificationsInOneDriveForBusinessEnabled  Property   bool NotificationsInOneDriveForBusinessEnabled {get;}                                                              
NotificationsInSharePointEnabled           Property   bool NotificationsInSharePointEnabled {get;}                                                                       
NotifyOwnersWhenInvitationsAccepted        Property   bool NotifyOwnersWhenInvitationsAccepted {get;}                                                                    
NotifyOwnersWhenItemsReshared              Property   bool NotifyOwnersWhenItemsReshared {get;}                                                                          
ODBAccessRequests                          Property   Microsoft.SharePoint.Client.SharingState ODBAccessRequests {get;}                                                  
ODBMembersCanShare                         Property   Microsoft.SharePoint.Client.SharingState ODBMembersCanShare {get;}                                                 
OfficeClientADALDisabled                   Property   bool OfficeClientADALDisabled {get;}                                                                               
OneDriveForGuestsEnabled                   Property   bool OneDriveForGuestsEnabled {get;}                                                                               
OneDriveStorageQuota                       Property   double OneDriveStorageQuota {get;}                                                                                 
OrphanedPersonalSitesRetentionPeriod       Property   int OrphanedPersonalSitesRetentionPeriod {get;}                                                                    
OwnerAnonymousNotification                 Property   bool OwnerAnonymousNotification {get;}                                                                             
PermissiveBrowserFileHandlingOverride      Property   bool PermissiveBrowserFileHandlingOverride {get;}                                                                  
PreventExternalUsersFromResharing          Property   bool PreventExternalUsersFromResharing {get;}                                                                      
ProvisionSharedWithEveryoneFolder          Property   bool ProvisionSharedWithEveryoneFolder {get;}                                                                      
PublicCdnAllowedFileTypes                  Property   string PublicCdnAllowedFileTypes {get;}                                                                            
PublicCdnEnabled                           Property   bool PublicCdnEnabled {get;}                                                                                       
PublicCdnOrigins                           Property   System.Collections.Generic.IList[Microsoft.Online.SharePoint.PowerShell.SPOPublicCdnOrigin] PublicCdnOrigins {get;}
RequireAcceptingAccountMatchInvitedAccount Property   bool RequireAcceptingAccountMatchInvitedAccount {get;}                                                             
RequireAnonymousLinksExpireInDays          Property   int RequireAnonymousLinksExpireInDays {get;}                                                                       
ResourceQuota                              Property   double ResourceQuota {get;}                                                                                        
ResourceQuotaAllocated                     Property   double ResourceQuotaAllocated {get;}                                                                               
SearchResolveExactEmailOrUPN               Property   bool SearchResolveExactEmailOrUPN {get;}                                                                           
SharingAllowedDomainList                   Property   string SharingAllowedDomainList {get;}                                                                             
SharingBlockedDomainList                   Property   string SharingBlockedDomainList {get;}                                                                             
SharingCapability                          Property   Microsoft.Online.SharePoint.TenantManagement.SharingCapabilities SharingCapability {get;}                          
SharingDomainRestrictionMode               Property   Microsoft.Online.SharePoint.TenantManagement.SharingDomainRestrictionModes SharingDomainRestrictionMode {get;}     
ShowAllUsersClaim                          Property   bool ShowAllUsersClaim {get;}                                                                                      
ShowEveryoneClaim                          Property   bool ShowEveryoneClaim {get;}                                                                                      
ShowEveryoneExceptExternalUsersClaim       Property   bool ShowEveryoneExceptExternalUsersClaim {get;}                                                                   
ShowPeoplePickerSuggestionsForGuestUsers   Property   bool ShowPeoplePickerSuggestionsForGuestUsers {get;}                                                               
SignInAccelerationDomain                   Property   string SignInAccelerationDomain {get;}                                                                             
SpecialCharactersStateInFileFolderNames    Property   Microsoft.Online.SharePoint.TenantManagement.SpecialCharactersState SpecialCharactersStateInFileFolderNames {get;} 
StartASiteFormUrl                          Property   string StartASiteFormUrl {get;}                                                                                    
StorageQuota                               Property   long StorageQuota {get;}                                                                                           
StorageQuotaAllocated                      Property   long StorageQuotaAllocated {get;}                                                                                  
UseFindPeopleInPeoplePicker                Property   bool UseFindPeopleInPeoplePicker {get;}                                                                            
UsePersistentCookiesForExplorerView        Property   bool UsePersistentCookiesForExplorerView {get;}                                                                    
UserVoiceForFeedbackEnabled                Property   bool UserVoiceForFeedbackEnabled {get;}   

Hi Sam,

As given above GM list, both are objects which has multiple properties, My objective is to compare each property value with RLD and Current to store the difference for further processing. I don’t want to specify each property like $RLD_SPOT.Property1, $RLD_SPOT.Property2… etc… should be get in to loop and compare one by one.