rewrite below Bash code to Powershell

echo "### Database instance counter ###"             
                instancecounter=$(echo "$DB_INSTANCES" | wc -w)
                IFS=' ' read -r -a DB_INSTANCES_ARRAY <<< "$DB_INSTANCES"
                echo "Databases found: $instancecounter"

                for i in "${!DB_INSTANCES_ARRAY[@]}"
                do
                    echo "database$i: ${DB_INSTANCES_ARRAY[$i]}"
                done

                echo -e "### Current catalog ###"
                pwd

                echo -e "### Copying templates to config file ###"
                mkdir $(Build.ArtifactStagingDirectory)/_config
                touch $(Build.ArtifactStagingDirectory)/_config/application.properties

                cat ./_pipelines/_appConfigs/appconfig.runtime-variables.template >> $(Build.ArtifactStagingDirectory)/_config/application.properties
                for i in "${!DB_INSTANCES_ARRAY[@]}"
                do
                  echo "application.db.database$i=${DB_INSTANCES_ARRAY[$i]}" >> $(Build.ArtifactStagingDirectory)/_config/application.properties
                done
                echo -e "\n\n" >> $(Build.ArtifactStagingDirectory)/_config/application.properties
                cat ./_pipelines/_appConfigs/appconfig.application-settings.template >> $(Build.ArtifactStagingDirectory)/_config/application.properties
                cat ./_pipelines/_appConfigs/appconfig.ssl-settings.template >> $(Build.ArtifactStagingDirectory)/_config/application.properties
                cat ./_pipelines/_appConfigs/appconfig.database-general-settings.template >> $(Build.ArtifactStagingDirectory)/_config/application.properties
                for i in "${!DB_INSTANCES_ARRAY[@]}"
                do
                    echo -e "Destination server: $DESTINATION_SERVER"
                    if [[ $DESTINATION_SERVER == clrv* ]]
                    then
                      echo -e "\tselecting linux template"
                      template="./_pipelines/_appConfigs/appconfig.database-connection-settings-linux.template"
                    elif [[ $DESTINATION_SERVER == sx* ]]
                    then
                      echo -e "\tselecting wintel template"
                      template="./_pipelines/_appConfigs/appconfig.database-connection-settings-wintel.template"
                    fi

                    if [[ -n $template ]]
                    then
                      if [[ $i -eq 0 ]]
                      then
                        sed -e "s/{{i}}/$i/g" "$template" >> "$(Build.ArtifactStagingDirectory)/_config/application.properties"
                      else
                        sed -e "/#/d" -e "s/{{i}}/$i/g" "$template" >> "$(Build.ArtifactStagingDirectory)/_config/application.properties"
                      fi
                    fi

                  echo -e "\n" >> $(Build.ArtifactStagingDirectory)/_config/application.properties
                done
                cat ./_pipelines/_appConfigs/appconfig.application-integration.template >> $(Build.ArtifactStagingDirectory)/_config/application.properties

                echo -e "### Prepared application.properties file ###"
                cat $(Build.ArtifactStagingDirectory)/_config/application.properties