Public/Set-PurviewSensitivityLabelLocale.ps1
|
function Set-PurviewSensitivityLabelLocale { <# .SYNOPSIS The function configures multilanguage Display Names and Tooltips of a sensitivity label. .DESCRIPTION The function configures multilanguage Display Names and Tooltips of a sensitivity label. For details see repository folder's README.md .PARAMETER Name [String] The string $Name represents the unique sensitivity label name. .PARAMETER Languages [Array] The array $Languages represents the languages to process. Languages must be provided as 2-2 language/country code (e.g. en-us) .PARAMETER DisplayNames [Array] The array $DisplayNamnes represents the display names of the sensitivity label for each configured language. .PARAMETER Tooltips [Array] The array $Tooltips represents the tooltipss of the sensitivity label for each configured language. .OUTPUTS System.Boolean .NOTES The function requires the ExchangeOnlineManagement PowerShell module to work. To connect to Security & Compliance use cmdlet 'Connect-IPPSSession' instead of 'Connect-ExchangeOnline'. .EXAMPLE $Name = "P_01" $Languages = "en-us","de-de" $DisplayNames = "Public","Öffentlich" $Tooltips = "Public documents","Öffentliche Dokumente" Set-PurviewSensitivityLabelLocale -Name $Name -Languages $Languages -DisplayNames $DisplayNames -Tooltips $Tooltips #> [CmdletBinding(PositionalBinding=$false,HelpUri="https://github.com/uplink-systems/powershell-modules/UplinkSystems.Microsoft.Cloud")] [Alias("Set-SensitivityLabelLocale")] param( [Parameter(Mandatory=$true, Position=0)] [String] $Name, [Parameter(Mandatory=$true)] [Array] $Languages, [Parameter(Mandatory=$true)] [Array] $DisplayNames, [Parameter(Mandatory=$true)] [Array] $Tooltips ) # verify matching array value counts if (-not(($DisplayNames.Count, $Tooltips.Count -eq $Languages.Count).Count -eq 2)) {return $false} # build 'displayName' value $DisplayNameLocaleSettings = [PSCustomObject]@{LocaleKey='displayName'; Settings=@( for ( $Index = 0; $Index -lt $Languages.Count; $Index = $Index + 1) { @{key=$Languages[$Index];Value=$DisplayNames[$Index];} } ) } # build 'tooltip' value $TooltipLocaleSettings = [PSCustomObject]@{LocaleKey='tooltip'; Settings=@( for ( $Index = 0; $Index -lt $Languages.Count; $Index = $Index + 1) { @{key=$Languages[$Index];Value=$Tooltips[$Index];} } ) } # update label's locale settings with new 'displayName'- and 'tooltip' values Set-Label -Identity $Name -LocaleSettings (ConvertTo-Json $DisplayNameLocaleSettings -Depth 2 -Compress),(ConvertTo-Json $TooltipLocaleSettings -Depth 2 -Compress) | Out-Null # verify that label's locale settings contain all new values $LabelLocaleSettings = (Get-Label -Identity $Name).LocaleSettings $LanguagesCount = 0 foreach ($Language in $Languages) {if ($LabelLocaleSettings -like "*$($Language)*") {$LanguagesCount = $LanguagesCount + 1}} $DisplayNamesCount = 0 foreach ($DisplayName in $DisplayNames) {if ($LabelLocaleSettings -like "*$($DisplayName)*") {$DisplayNamesCount = $DisplayNamesCount + 1}} $TooltipsCount = 0 foreach ($Tooltip in $Tooltips) {if ($LabelLocaleSettings -like "*$($Tooltip)*") {$TooltipsCount = $TooltipsCount + 1}} if (($LanguagesCount -eq $Languages.Count) -and ($DisplayNamesCount -eq $DisplayNames.Count) -and ($TooltipsCount -eq $Tooltips.Count)) {return $true} else {return $false} } |