Using SQL Server 2008 R2 and Powershell 2.0
I have created a hash of options that I want to set in a SQL Server database like so:
$dbopts = @{
"AutoCreateStatistics"=$true;
"AutoUpdateStatistics"=$true;
"AutoShrink"=$false;
};
I want to set these options on a SQL Server database using SMO. I created a function which accepts a SMO Database object and the DatabaseOptions hash as inputs.
function setDatabaseOptions {
param ($db, $opts);
foreach ($opt in $db.DatabaseOptions) {
# what to write here?
}
}
I want to set the options in the hash to the database. Not sure the best way to do this. Any suggestions? An example, to set an option explicitly you would do
$db.DatabaseOptions.AutoCreateStatistics = $true
With no disrespect to Shay as in his last comment try to enumerate the hashtable.