-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStart-ServerAssetScan.ps1
More file actions
91 lines (75 loc) · 3.56 KB
/
Copy pathStart-ServerAssetScan.ps1
File metadata and controls
91 lines (75 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ValidationTags#Messaging,FlowControl,Pipeline,CodeStyle#
function Start-ServerAssetScan {
<#
.SYNOPSIS
Runs the Asset analysis against all servers listed as an Asset.
.DESCRIPTION
Runs an asset management analysis against all servers loaded to the Assets Table in ITAM.
The scan inludes the gathering hardware configuration, SQL Configurations, and more.
.PARAMETER WhatIf
Shows what would happen if the command were to run. No actions are actually performed.
.EXAMPLE
PS C:\> Start-ServerAssetScan
Runs a scan against all systems listed in the Assets Table
#>
begin{
$CleanUpSQL = "
Exec ITAM.dbo.Cleanup_Staging_Tables
"
$sql = "Select
a.Asset_ID, a.Asset_Name, a.Asset_type from ITAM.dbo.Asset a where a.Asset_Name <> 'Dev-Server1'
"
}
process{
#Clean up old records in the staging location prior to next asset scan
Invoke-DbaQuery -SqlInstance Localhost -Database ITAM -Query $CleanUpSQL
#Get a list of all servers for the asset scan
$Servers = Invoke-DbaQuery -ServerInstance Localhost -Database ITAM -Query $sql
#Set Asset status to runnin
#loop through the result set and run the asset scan.
foreach ($Server in $Servers) {
try {
Get-ServerResourceInfo -AssetID $Server.Asset_ID -AssetName $Server.Asset_Name $Server.Asset_type
} catch {
$ErrorMessage = $_.Exception.Message
Invoke-DbaQuery -SqlInstance Localhost -Database ITAM -Query $UpdateToFailed
Write-Error -Message $ErrorMessage -ErrorAction Stop
}
try {
Get-InstalledUpdates -AssetID $Server.Asset_ID -AssetName $Server.Asset_Name $Server.Asset_type
} catch {
$ErrorMessage = $_.Exception.Message
Invoke-DbaQuery -SqlInstance Localhost -Database ITAM -Query $UpdateToFailed
Write-Error -Message $ErrorMessage -ErrorAction Stop
}
try {
Get-DatabaseConfigurationInfo -AssetID $Server.Asset_ID -AssetName $Server.Asset_Name $Server.Asset_type
} catch {
$ErrorMessage = $_.Exception.Message
Invoke-DbaQuery -SqlInstance Localhost -Database ITAM -Query $UpdateToFailed
Write-Error -Message $ErrorMessage -ErrorAction Stop
}
try {
Get-SQLAgentJobStatus -AssetID $Server.Asset_ID -AssetName $Server.Asset_Name $Server.Asset_type
} catch {
$ErrorMessage = $_.Exception.Message
Invoke-DbaQuery -SqlInstance Localhost -Database ITAM -Query $UpdateToFailed
Write-Error -Message $ErrorMessage -ErrorAction Stop
}
try {
Get-ErrorLogInfo -AssetID $Server.Asset_ID -AssetName $Server.Asset_Name $Server.Asset_type
} catch {
$ErrorMessage = $_.Exception.Message
Invoke-DbaQuery -SqlInstance Localhost -Database ITAM -Query $UpdateToFailed
Write-Error -Message $ErrorMessage -ErrorAction Stop
}
try {
Get-DiskDriveSpace -AssetID $Server.Asset_ID -AssetName $Server.Asset_Name $Server.Asset_type
} catch {
$ErrorMessage = $_.Exception.Message
Invoke-DbaQuery -SqlInstance Localhost -Database ITAM -Query $UpdateToFailed
Write-Error -Message $ErrorMessage -ErrorAction Stop
}
}
}
}