Oct 19 2022 01:10 PM
Hello friends,
First of all, I apologize for the words, but I don't speak English and I rely on an online translator.
Well, I have a doubt and I believe it is of orientation. Still learning to use Powershell in the "force" 😉
I need - I'm trying - to extract data from fields in different commands/modules...
Through Get-SPOSite -Identity https://mytenet.sharepoint.com/sites/mysite I look for the Owner. In some cases it brings me the email of the user who created/is the Owner and that satisfies me.
In other cases it tells me the ID of the Group that created/originates the site.
From the ID I do the following:
Get-UnifiedGroup -Identity [Group ID] | Select ManagedBy
As I need this in a report, I started doing it like this:
Get-SPOSite -Identity https://mytenet.sharepoint.com/sites/mysite | ForEach-Object -Process {
[PSCustomObject][Ordered]@{
Url = $PSItem.Url
'Owner' = Get-UnifiedGroup -Identity [Group ID] | Select-Object -Property @{Name = 'Owner'; Expression={$PSItem.ManagedBy}}
'Usage' = $PSItem.StorageUsageCurrent
'Space' = $PSItem.StorageQuota
'Last Access' = $PSItem.LastContentModifiedDate
}
}
I wanted to understand why he always returns the Owner field to me
Url : https://mytenet.sharepoint.com/sites/mysite
Owner : @{Owner=name.user}
Usage : 1
Space: 5120
Last Access: 10/19/2022 18:15:26
And sometimes something like "system.collections.arraylist" or similar.
Thank you very much in advance for your help and guidance!!!
Big Hugs!!
Oct 19 2022 04:34 PM
So, the reason it looks that way is because a group can have multiple managers (or owners), which you can see when you check the type of the ManagedBy field.
Despite the complicated type name, in reality, it's just an array of strings, meaning we can use PowerShell operators like "-join" to join all of the string members together as the example below shows.
So, putting this together with your example code:
# Original line.
'Owner' = Get-UnifiedGroup -Identity [Group ID] | Select-Object -Property @{Name = 'Owner'; Expression={$PSItem.ManagedBy}}
# Changes very slightly at the end to this line.
'Owner' = Get-UnifiedGroup -Identity [Group ID] | Select-Object -Property @{Name = 'Owner'; Expression={$PSItem.ManagedBy -join ", "}}
Also, for someone only starting to learn PowerShell, you're doing very, very well! Keep up the great work!
Cheers,
Lain
Oct 25 2022 04:47 AM
Dec 15 2022 04:28 AM
SolutionOlá Amigos...
Eu descobri como "se livrar" de conteúdo indesejado na tela.
No final da linha, uso uma referência ao objeto que desejo que seja exibido "| Select-Object -ExpandProperty 'NomeObjeto' " ...
O Script na pergunta tem esta aparência:
$CSV = Import-Csv .\Lista-SITEGRP.csv
$CSV. Conte
$CSV. | do proprietário ForEach-Object {
Get-UnifiedGroup -Identity $_ | ForEach-Object -Process {[PSCustomObject][Ordered]@{
Url = $PSItem.SharePointSiteUrl'Owner
' = $PSItem.ManagedBy -join ", "
'StorageQuota' = Get-SPOSite -Identity $_. | SharePointSiteUrl Select-Object -Property @{Name = 'StorageQuota'; Expression={ $PSItem.StorageQuota}} | Select-object -expandProperty 'StorageQuota''StorageUsageCurrent'
= Get-SPOSite -Identity $_. | SharePointSiteUrl Select-Object -Property @{Name = 'StorageUsageCurrent'; Expression={ $PSItem.StorageUsageCurrent}} | Select-object -expandProperty 'StorageUsageCurrent''Template'
= Get-SPOSite -Identity $_. | SharePointSiteUrl Select-Object -Property @{Name = 'Template'; Expression={ $PSItem.Template}} | Select-Object -ExpandProperty 'Template''LocaleId'
= Get-SPOSite -Identity $_. | SharePointSiteUrl Select-Object -Property @{Name = 'LocaleId'; Expression={ $PSItem.LocaleId}} | Select-Object -ExpandProperty 'LocaleId'
}
}
}
Muito obrigado a todos pela vossa ajuda e atenção!!!
Grande abraço
Dec 15 2022 04:28 AM
SolutionOlá Amigos...
Eu descobri como "se livrar" de conteúdo indesejado na tela.
No final da linha, uso uma referência ao objeto que desejo que seja exibido "| Select-Object -ExpandProperty 'NomeObjeto' " ...
O Script na pergunta tem esta aparência:
$CSV = Import-Csv .\Lista-SITEGRP.csv
$CSV. Conte
$CSV. | do proprietário ForEach-Object {
Get-UnifiedGroup -Identity $_ | ForEach-Object -Process {[PSCustomObject][Ordered]@{
Url = $PSItem.SharePointSiteUrl'Owner
' = $PSItem.ManagedBy -join ", "
'StorageQuota' = Get-SPOSite -Identity $_. | SharePointSiteUrl Select-Object -Property @{Name = 'StorageQuota'; Expression={ $PSItem.StorageQuota}} | Select-object -expandProperty 'StorageQuota''StorageUsageCurrent'
= Get-SPOSite -Identity $_. | SharePointSiteUrl Select-Object -Property @{Name = 'StorageUsageCurrent'; Expression={ $PSItem.StorageUsageCurrent}} | Select-object -expandProperty 'StorageUsageCurrent''Template'
= Get-SPOSite -Identity $_. | SharePointSiteUrl Select-Object -Property @{Name = 'Template'; Expression={ $PSItem.Template}} | Select-Object -ExpandProperty 'Template''LocaleId'
= Get-SPOSite -Identity $_. | SharePointSiteUrl Select-Object -Property @{Name = 'LocaleId'; Expression={ $PSItem.LocaleId}} | Select-Object -ExpandProperty 'LocaleId'
}
}
}
Muito obrigado a todos pela vossa ajuda e atenção!!!
Grande abraço