I've got a variable, with the following string values:
PS C:\> $sql.physicalname
I:\Data\Data1.mdf
I:\Data\Data2.ndf
I:\Data\Data3.ndf
I:\Data\Data4.ndf
I:\Data\Data5.ndf
I:\Data\Data6.ndf
I:\Data\Data7.ndf
I:\Data\Data8.ndf
I:\Data\Data9.ndf
I:\Data\log.ldf
What I want is to replace/trim the strings so that only the .mdf/.ndf/.ldf extensions remain:
.mdf
.ndf
.ndf
.ndf
.ndf
.ndf
.ndf
.ndf
.ndf
.ldf
I tried using the -replace parameter with the * wildcard, but I cant wrap my head around it.
As it is a regular expression you pass to -replace, try it e.g. with
-replace ".*\.", "."
A better and more robust way would be to use something like that
$sql.physicalname | % { [System.IO.Path]::GetExtension($_) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With