Author Posts

April 19, 2017 at 8:02 am

ok so i thought this would work but im getting a strange result

so i have

$DBS = Get-ChildItem "C:\ExchangeDatabases" -Recurse | where {$_.extension -eq ".db"} | select fullname

producing the below $dbs


##which looks like

#now i want to replace the ".db" with ".yes"

$output3 = foreach ($DB in $DBs)
    $log = $db -replace".db", ".yes" 

                        6 = $log


but my output shows like this


why is it replacing the "_db" in the string aswell as the ".db", aslo i want to get rid of the @{Fullname=}

April 19, 2017 at 8:22 am

Found it

using the $ in ".db"

$log2 = $db -replace ".db$", ".yes"

April 19, 2017 at 8:25 am

Use single quotes for replacement if you haven't plans for $variables in replace

April 19, 2017 at 8:32 am

May I suggest some changes?

$DBS = Get-ChildItem 'c:\ExchangeDatabases' -Filter *.db -Recurse 

$output = foreach ($DB in $DBs)
        'Logfile' = Join-Path -Path $DB.Directory -ChildPath ($DB.BaseName + ".log")

April 19, 2017 at 9:26 am

Many thanks both for suggestions 🙂

April 19, 2017 at 2:22 pm

...and... '.' in regex matches any symbol, if you want match only real period symbol you should use '\.'. that the cause of you initial problem

April 20, 2017 at 8:04 am

Thanks Max, Regex is a black art 🙂