User Tools

Site Tools


windows:powershell:insertinstance

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

windows:powershell:insertinstance [2013/10/14 22:19]
haidong Got the right PowerShell code this time.
windows:powershell:insertinstance [2018/05/14 22:00]
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. 
  
-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. 
- 
-** Remember to change "​sql1"​ to your host instance name ** 
- 
-<code powershell updateInstance.ps1>​ 
-$InstanceList = Invoke-Sqlcmd -Query "exec Windows.Instance_Select_InstanceID_InstanceName"​ -ServerInstance "​sql1"​ -Database "​SysMetrics"​ 
-$InstanceList | ForEach-Object { 
- 
-    $InstanceName = $_.InstanceName 
-    $InstanceID = $_.InstanceID 
- 
-        Try { 
-           ​$result = Invoke-Sqlcmd -ServerInstance $InstanceName -Query "​SELECT SERVERPROPERTY('​Edition'​)"​ 
-           ​$InstanceEdition = $result.column1 
-           ​$result = Invoke-Sqlcmd -ServerInstance $InstanceName -Query "​SELECT 
-SERVERPROPERTY('​EditionID'​)"​ 
-           ​$InstanceEditionID = $result.column1 
-           ​$result = Invoke-Sqlcmd -ServerInstance $InstanceName -Query "​SELECT SERVERPROPERTY('​ProductVersion'​)"​ 
-           ​$InstanceVersion = $result.column1 
-           ​$result = Invoke-Sqlcmd -ServerInstance $InstanceName -Query "​SELECT SERVERPROPERTY('​ProductLevel'​)"​ 
-           ​$InstanceServicePack = $result.column1 
- 
-           $sql = "EXEC Windows.Instance_Update $InstanceID,​ 
-'​$InstanceEdition',​ '​$InstanceEditionID',​ '​$InstanceVersion',​ '​$InstanceServicePack'"​ 
-           ​Invoke-Sqlcmd -Query $sql -ServerInstance "​sql1"​ -Database "​SysMetrics"​ 
-        } 
-    Catch { Return } 
-} 
-</​code>​ 
windows/powershell/insertinstance.txt ยท Last modified: 2018/05/14 22:00 (external edit)