I haven't been on here for a while so apologies if I have made any faux pas in my question...
I am writing a small PS script that will update some tables in an SQL database. I would like to return the current data in the table and then ask the user if this needs changing.
Heres my code so far:
Get-SqlDatabase -serverinstance localhost | Out-GridView -PassThru -Title "Select Database to work on." | New-Variable DB -Force | FT -AutoSize
$DB.ExecuteWithResults("SELECT FileServerPath AS 'Current DMS Path' FROM DMSAdministration").tables
Switch(Read-Host "Would you like to change this?")
{
Y {Write-Host -f Green "Begin Update DMS Path..."
$DMSPath = Read-Host "Please enter DMS Path for $DB"
[string]$SQLCMD = "UPDATE DMSadministration SET FileServerPath = '$DMSPath' WHERE ConfigurationID = 'CONFIG1'"
$DB.ExecuteNonQuery($SQLCMD)
$DB.ExecutewithResults("SELECT FileServerPath FROM DMSAdministration").tables
}
N {Write-Host -f Yellow "Did not alter path!"}
}
The problem i'm having is that when I run this I select the database from Out-GridView. I then expect it to show me the result from $DB.ExecuteWithResults("SELECT FileServerPath AS 'Current DMS Path' FROM DMSAdministration").tables
and then ask the user whether this should be changed.
Currently, I select the DB and the Switch condition runs before the result is given.
TIA