Author Posts

September 29, 2016 at 11:23 am

Can never bend my head around these scenarios

Get-Mailbox Hello.UK.Pensions | select grantsendonbehalfto -ExpandProperty grantsendonbehalfto

Gives me the below

{global.xxxx.com/Europe/United Kingdom/London Campus/Human Resources/Human Resources (Europe)/Users/Elaine Bates}

How do i only select all charectors after the last "/" except the "}", so in this case to end up withe "Elaine Bates"

thanks

September 29, 2016 at 11:50 am

'{global.xxxx.com/Europe/United Kingdom/London Campus/Human Resources/Human Resources (Europe)/Users/Elaine Bates}' -match '.*/(.+)}'
$Matches[1]

September 29, 2016 at 11:59 am

(Get-Mailbox Hello.UK.Pensions | select -ExpandProperty grantsendonbehalfto) -split '/' | select -Last 1

September 29, 2016 at 12:01 pm

you'll have to foreach and join for any that include multiples.

September 29, 2016 at 12:10 pm

thanks Olaf

thats great, however if i get multipe results ?

{global.xxxx.com/Europe/United Kingdom/London Campus/Human Resources/Human Resources (Europe)/Users/Elaine Bates}
{global.xxxx.com/Europe/United Kingdom/Newcastle/Users/Mark Prior}

need something with intelligence to pick out more than one name and ideally put it into a string or text file

September 29, 2016 at 12:14 pm

$results = (Get-Mailbox hello.UK.Pensions | select -ExpandProperty grantsendonbehalfto) 

$names = foreach ($result in $results)
{
$result -split '/' | select -Last 1 
}

Thanks both have the above working, best thing about PS is theres always more than one way to achieve what you want

  • This reply was modified 1 year, 12 months ago by  Mark Prior.

September 29, 2016 at 2:25 pm

If you want to join your results up use the [string]::join(string separator, string[] values) method.

$Results = Get-Mailbox Hello.UK.Pensions | select grantsendonbehalfto -ExpandProperty grantsendonbehalfto
$ArrResults = $Results | ForEach-Object {$_ -split '/' | Select -Last 1}

# If you want to join them then use [string]::join(string seperator, string[] values)
$FriendlyResult = [string]::Join(', ', $ArrResults)

Liam

September 29, 2016 at 2:50 pm

thanks liam, not needed but im sure i will use later down the line 🙂