This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
windows:powershell:insertinstance [2013/10/15 14:56] haidong Correct PowerShell script, finally. |
windows:powershell:insertinstance [2013/11/04 21:20] haidong Change SysMetrics to JiMetrics |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | Here is a PowerShell script to discover SQL Server instances installed on the server hosts in the Host table. The domain account that this job runs under needs to in the local administrator's group on the host whose metrics it is trying to get. | + | Here is a PowerShell script to discover SQL Server instances installed on the server hosts in the Host table. Please create a SQL Server Agent job for this. The domain account that this job runs under needs to in the local administrator's group on the host whose metrics it is trying to get. |
This information should be fairly static. Depending on your situation, scheduling this to run weekly, monthly, or quarterly, or whatever. You can always manually kick off this job if needed. | This information should be fairly static. Depending on your situation, scheduling this to run weekly, monthly, or quarterly, or whatever. You can always manually kick off this job if needed. | ||
Line 5: | Line 5: | ||
** Remember to change "sql1" to your host instance name ** | ** Remember to change "sql1" to your host instance name ** | ||
- | <code powershell updateInstance.ps1> | + | <code powershell insertInstance.ps1> |
function getSqlInstanceName($ComputerName) | function getSqlInstanceName($ComputerName) | ||
{ | { | ||
- | $SqlInstances = Get-Service -ComputerName $ComputerName | where {($_.Name -like | + | $SqlInstances = Get-Service -ComputerName $ComputerName | where {($_.Name -like |
'mssql$*') -or ($_.Name -eq 'mssqlserver')} | 'mssql$*') -or ($_.Name -eq 'mssqlserver')} | ||
$instanceNameArray = New-Object System.Collections.ArrayList | $instanceNameArray = New-Object System.Collections.ArrayList | ||
Line 27: | Line 27: | ||
} | } | ||
$HostList = Invoke-Sqlcmd -ServerInstance "sql1" -Query "EXEC | $HostList = Invoke-Sqlcmd -ServerInstance "sql1" -Query "EXEC | ||
- | Windows.Host_Select_HostID_HostName" -Database "SysMetrics" | + | Windows.Host_Select_HostID_HostName" -Database "JiMetrics" |
$HostList | foreach { | $HostList | foreach { | ||
$HostID = $_.HostID | $HostID = $_.HostID | ||
Line 44: | Line 44: | ||
'$IsActive'" | '$IsActive'" | ||
Invoke-Sqlcmd -Query $sql -ServerInstance "sql1" -Database ` | Invoke-Sqlcmd -Query $sql -ServerInstance "sql1" -Database ` | ||
- | "SysMetrics" | + | "JiMetrics" |
} | } | ||
} | } | ||
} | } | ||
</code> | </code> |