locked
Removing Text from Array Output RRS feed

  • Question

  • Hi,

    I am trying to remove the first 4 characters from the output from my array. I have been doing some researching and having a play about and the below does't produce any errors, but still adds the sip: at the beginning of each line of the output. Any ideas how to get this to do what I want it to please?

    $oldarray=Get-CsUser | Where-Object {$_.HostingProvider -eq "sipfed.online.lync.com"} | Select-Object -Property sipaddress | Out-String
    $newarray=$oldarray | ForEach-Object {$_.Remove(0,1)}
    $newarray
    This still outputs sip:first.last@domain.com


    Tuesday, June 4, 2019 2:47 PM

Answers

  • With SIP: we can also use the "replace" operator.

    $_ -replace '^SIP:'

    To do this for "n" characters use "SubString".

    or

    $_ -replace '....'


    \_(ツ)_/

    • Marked as answer by Blue_man2 Tuesday, June 4, 2019 3:32 PM
    Tuesday, June 4, 2019 3:13 PM

All replies

  • If you want to get rid of "sip:" you could use the -split operator
    ('sip:first.last@domain.com' -split ':')[1]

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, June 4, 2019 3:07 PM
  • With SIP: we can also use the "replace" operator.

    $_ -replace '^SIP:'

    To do this for "n" characters use "SubString".

    or

    $_ -replace '....'


    \_(ツ)_/

    • Marked as answer by Blue_man2 Tuesday, June 4, 2019 3:32 PM
    Tuesday, June 4, 2019 3:13 PM
  • Thanks the below worked

    $oldarray=Get-CsUser | Where-Object {$_.HostingProvider -eq "sipfed.online.lync.com"} | Select-Object -Property sipaddress | Out-String
    $newarray=$oldarray | ForEach-Object {$_-Replace"sip:"}
    $newarray


    Tuesday, June 4, 2019 3:33 PM