It is possible to replace "\"

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Dominique Hofmann Dominique Hofmann 3 years, 5 months ago.

  • Author
    Posts
  • #11415
    Profile photo of Dominique Hofmann
    Dominique Hofmann
    Participant

    Hello together
    I habe a array which contains "\Hofdo" and i want to replace the "\" with "" but if i try to replace it with the code:
    $Owner -replace "\", "" it doesn't work

    How can i replace it ?

  • #11416
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    PowerShell's -replace operator takes a regular expression as the first argument, and backslashes are special characters. On a side note, when the second argument is an empty string, it's optional, so you can do it like this:

    $Owner -replace '\\'
    
  • #11417
    Profile photo of Dominique Hofmann
    Dominique Hofmann
    Participant

    thanks

  • #11419
    Profile photo of Dominique Hofmann
    Dominique Hofmann
    Participant

    Hello again
    i try to find out the E-Mail-adress from an owner of a folder.
    I have a list with Owner of folders and i have already a script where i can search the e-mail of a single person but i want to search the e-mail of several person.
    Here is the script foreach-object{
    if($Owner -ne "Extra"){
    $User = Get-WmiObject -Query "SELECT * FROM ds_user where ds_sAMAccountName='$Owner'" -Namespace "root\Directory\LDAP"
    $Email = $user.DS_mail

    }
    }

    And the contain of the list is so:
    @{Extra}
    @{Hofdo}
    @{Kunfa}
    @{Visne}
    @{KIP}

You must be logged in to reply to this topic.