I need to create a CSV file and export it into a folder.
These are our requirements...
This is how far I've got
$identity = Get-OrganizationConfig | Select identity
Export-Csv <path>\$identity.csv
The file name is "@{Identity=COMPANY.onmicrosoft.com}.csv
.
How do I select the start of the tenant name?
The first issue is that Select-Object Identity
creates a new object with an Identity
property. If you just want the value of the Identity
property, use Select-Object -ExpandProperty
:
$identity = Get-OrganizationConfig | Select -ExpandProperty Identity
To remove the last part of the tenant FQDN, you could use the -replace
regex operator:
$identity = $identity -replace '\.onmicrosoft\.com$'
or the String.Replace()
method:
$identity = $identity.Replace('.onmicrosoft.com')
If you want to capitalize the first letter in the tenant name, you could use CultureInfo.TextInfo.ToTitleCase()
:
$identity = (Get-Culture).TextInfo.ToTitleCase($identity)