It is possible to replace "\"

This topic contains 3 replies, has 2 voices, and was last updated by  Dominique Hofmann 4 years, 7 months ago.

  • Author
  • #11415

    Dominique Hofmann

    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

    Dave Wyatt

    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

    Dominique Hofmann


  • #11419

    Dominique Hofmann

    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:

You must be logged in to reply to this topic.