Technical Article

Delete SQL Instance name from default backup location

,

TO Run the script:

Copy the script

run the fun: getPath

Follow the instructions.

clear
function getPATH {
Param ([string]$name=(Read-Host "Enter Instancename"))
$length = $name;

 IF (!$length)
 {
  write-host "***** NO Input Provided.*****"
  Break
 }
 ELSE
{write-host "You entered***:"$name.ToUpper();}


$INSTALLSHAREDDIR = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -match 'INSTALLSHAREDDIR='} 
$pos = $INSTALLSHAREDDIR.IndexOf("=")
$leftPart = $INSTALLSHAREDDIR.Substring(0, $pos)
$rightPart = $INSTALLSHAREDDIR.Substring($pos+1)
#$leftPart
$rightPart = $rightPart  -replace '"', ""
#$rightPart
$rightPart = $rightPart + "\MSSQL11.$name"
#$rightPart


if (Test-Path $rightPart) {
     
      write-host "**** Folder Does Exist in the path **** "
      #Write-Host "Cleaning up target Script folder "$rightPart""
      #$result = $host.ui.PromptForChoice($title, $message, $options, 0) 
      #Remove-Item -Path "$rightPart" -Force -Recurse 
      #$rightPart

    }
 Else
 {
    write-host "****** Folder Does NOT Exist in the path *****"
    }


$title = "Delete Files"
$message = "Do you want to delete the remaining files in the folder?"

$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
    "Deletes all the files in the folder."

$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
    "Retains all the files in the folder."

$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0) 

switch ($result)
    {
        0 {"You selected Yes."}
        1 {"You selected No."}
    }



 if ($result -eq 0) {
     
      Write-Host "Cleaning up target Script folder "$rightPart""
      Remove-Item -Path "$rightPart" -Force -Recurse 
      $rightPart

    }
 Else
 {
    write-host "****** FOLDER Found in the Path but Instructed NOT to Delete. *****"
    }
}

Rate

3 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

3 (2)

You rated this post out of 5. Change rating