Forum Discussion
tcboeira
Oct 19, 2022Brass Contributor
Is the use of "$psitem" correct?
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 t...
- Dec 15, 2022
Olá 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
LainRobertson
Oct 19, 2022Silver Contributor
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
- tcboeiraOct 25, 2022Brass ContributorThank you very, very much for the clarification!!!
I confess that I get a little confused in the construction of the "command". And sometimes to see it working without understanding what is actually happening is even a little frustrating. although very cool
Well, I would like to share a doubt that is persistent...
When I use this way:
Get-SPOSite -Identity [My Site] | ForEach-Object -Process {
[PSCustomObject][Ordered]@{
Url = $PSItem.Url
'Owner' = Get-UnifiedGroup -Identity [ID] | Select-Object -Property @{Name = 'Owner'; Expression={ $PSItem.ManagedBy -join ", " }}
'Usage' = $PSItem.StorageUsageCurrent
'Space' = $PSItem.StorageQuota
'Last Access' = $PSItem.LastContentModifiedDate
}
}
My return in the Owner field has always been like this:
Owner : @{Owner=name1, name2, name3}
For example: If only "name1, name2, name3" came, when I import the CSV I can handle it and everything else...
IF it were such a reality,
Get-UnifiedGroup -Identity [id] | ForEach-Object -Process {
[PSCustomObject][Ordered]@{
Url = $PSItem.SharePointSiteUrl
'ID' = $PSItem.ExternalDirectoryObjectId
'Owner' = $PSItem.ManagedBy -join ", "
'uAccess' = $PSItem.WhenChanged
}
}
Success is guaranteed, but then I have difficulties mixing the results.
How do I get rid of the "@{Owner=" and "}" in the output of the first example? or rather... How do I understand the best way to do it?
Again, thank you so much for the help!!!- tcboeiraDec 15, 2022Brass Contributor
Olá 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