none
Powershell wildcard problem

    שאלה

  • (get-content c:\file.txt) |
    Foreach-Object {$_ -replace "cn=", ""} | 
    Foreach-Object {$_ -replace ",*", ""}

    contents of file.txt:
    CN=COMPUTERNAME,OU=ITOU,DC=domain,DC=com
    CN=COMPUTERNAME2,OU=DIFFRENTOU,DC=domain,DC=com

    The above is the code i run as a powershell script. and the goal is to take away cn= and , and everything behind ,
    So naturally i just replaced "cn=" with "" and ",*" with "". This, does not work as intended.

    what i am left with is:
    COMPUTERNAMEOU=ITOUDC=domainDC=com
    COMPUTERNAME2OU=DIFFRENTOUDC=domainDC=com

    How could i achieve my goal of only being left with:
    COMPUTERNAME
    COMPUTERNAME2

    please provide an explaination along with your suggested changes! Would be much obliged!

    יום שישי 17 פברואר 2012 13:30

תשובות

כל התגובות