This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
windows:powershell:insertinstanceconfig [2013/11/05 11:33] haidong created |
windows:powershell:insertinstanceconfig [2018/05/14 22:00] (current) |
||
|---|---|---|---|
| Line 4: | Line 4: | ||
| <code powershell insertInstanceConfig.ps1> | <code powershell insertInstanceConfig.ps1> | ||
| - | function getInstanceConfig($ServerInstance) | + | function getInstanceConfig($ServerInstance) { |
| - | { | + | |
| $InstanceConfigQuery = @" | $InstanceConfigQuery = @" | ||
| SELECT [configuration_id] | SELECT [configuration_id] | ||
| Line 21: | Line 20: | ||
| $myHashtable = @{Configuration_Id = $_.configuration_id; Name = | $myHashtable = @{Configuration_Id = $_.configuration_id; Name = | ||
| $_.name; Value = $_.value; ValueInUse = $_.value_in_use} | $_.name; Value = $_.value; ValueInUse = $_.value_in_use} | ||
| - | [void] $dataIndexArray.add($myHashtable) | + | [void] $dataIndexArray.add($myHashtable)} |
| - | } | + | $dataIndexArray} |
| - | $dataIndexArray | + | |
| - | } | + | function insertInstanceConfigSQL($instanceConfig, $instanceID) { |
| + | $ConfigurationId, $Name, $Value, $ValueInUse = | ||
| + | $instanceConfig.Configuration_Id, $instanceConfig.Name, $instanceConfig.Value, $instanceConfig.ValueInUse | ||
| + | $sql = "EXEC Windows.InstanceConfig_Insert $InstanceID, $ConfigurationId, '$Name', '$Value', '$ValueInUse'" | ||
| + | return $sql} | ||
| $InstanceList = Invoke-Sqlcmd -Query "exec Windows.Instance_Select_InstanceID_InstanceName" -ServerInstance "sql1" -Database "JiMetrics" | $InstanceList = Invoke-Sqlcmd -Query "exec Windows.Instance_Select_InstanceID_InstanceName" -ServerInstance "sql1" -Database "JiMetrics" | ||
| Line 32: | Line 35: | ||
| $InstanceID = $_.InstanceID | $InstanceID = $_.InstanceID | ||
| - | Try { | + | Try { |
| $InstanceConfigArray = getInstanceConfig($InstanceName) | $InstanceConfigArray = getInstanceConfig($InstanceName) | ||
| $InstanceConfigArray | ForEach-Object { | $InstanceConfigArray | ForEach-Object { | ||
| - | $ConfigurationId, $Name, $Value, $ValueInUse = | + | $sql = insertInstanceConfigSQL $_ $InstanceID |
| - | $_.Configuration_Id, $_.Name, $_.Value, $_.ValueInUse | + | Invoke-Sqlcmd -Query $sql -ServerInstance "sql1" -Database "JiMetrics"}} |
| - | + | Catch [Exception] { Continue }} | |
| - | $sql = "EXEC Windows.InstanceConfig_Insert $InstanceID, | + | |
| - | $ConfigurationId, '$Name', '$Value', '$ValueInUse'" | + | |
| - | Invoke-Sqlcmd -Query $sql -ServerInstance "sql1" -Database "JiMetrics" | + | |
| - | } | + | |
| - | } | + | |
| - | Catch { Return } | + | |
| - | } | + | |
| </code> | </code> | ||