# the current environment that we are deploying to$environmentName = $RedGateEnvironmentName;

# regular expression used to search for files to be renamed.# It matches files with names like '<fileName>.<environmentName>.<fileExt>'$searchRegex = "^(?<fileName>.*)\\.(?<$environmentName>.*)\\.(?<fileExt>.*)$";

# run the regular expression again on the file name to break the name into sub-parts specified in the regular expression. # It also saves the result in $matches variable $file.Name -match $searchRegex;

# New name for the file $newFileName = $matches.fileName + "." + "sql";

Write-Host "renaming $pathOfFileToRename to $newFileName";

# do a force rename (will overwrite any existing file with the new name) Move-Item $file.FullName (Join-Path $file.Directory $newFileName) -Force;}