This repository has been archived by the owner on Jun 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd-SCSMManagementPack.ps1
90 lines (77 loc) · 2.51 KB
/
Add-SCSMManagementPack.ps1
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
Function Add-SCSMManagementPack
{
<#
.SYNOPSIS
Create a new management pack
.DESCRIPTION
Create a new management pack
.PARAMETER mpName
The name of the new management pack.
.PARAMETER ComputerName
Specifies the SCSM server, as default localhost is used.
.EXAMPLE
Add-SCSMManagementPack -computerName 'Server1' -mpName 'My new Management Pack'
.INPUTS
String
.OUTPUTS
Create a new Management Pack in SCSM
Status is outputted to screen
.NOTES
Author: Wouter de Dood
Website:
Twitter: @WMouter
#>
[cmdletbinding()]
param (
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[string]$mpName,
[Parameter(ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[string]$ComputerName = 'localhost'
)
Begin
{
$ErrorActionPreference = 'Stop'
Try
{
Import-Module SMLets
}
Catch
{
Write-Output "[$(Get-Date -UFormat "%Y-%m-%d %H:%M:%S")] - [Error] Module not loaded, SMLets Module is mandatory."
Throw
}
}
Process
{
$ErrorActionPreference = 'Stop'
Try
{
Write-Output "[$(Get-Date -UFormat "%Y-%m-%d %H:%M:%S")] - [Action] Create $mpName Management Pack"
if (!(Get-SCManagementPack -ComputerName $computerName | where {$_.DisplayName -eq $mpName} ))
{
$newManagemenPackHash = @{
ComputerName = $computerName
FriendlyName = $mpName
DisplayName = $mpName
ManagementPackName = "managementpack.LC$((Get-Date).ToUniversalTime().Ticks)" #Create unique ID
}
New-SCManagementPack @newManagemenPackHash
Write-Output "[$(Get-Date -UFormat "%Y-%m-%d %H:%M:%S")] - [Status] Created"
}
else
{
Write-Output "[$(Get-Date -UFormat "%Y-%m-%d %H:%M:%S")] - [Status] No need to add already exists"
}
}
Catch
{
Write-Output "[$(Get-Date -UFormat "%Y-%m-%d %H:%M:%S")] - [Error] Not created!"
Write-Output "[$(Get-Date -UFormat "%Y-%m-%d %H:%M:%S")] - [Error] $($_.Exception.Message)"
}
}
End {
}
} #end Function Add-SCSMManagementPack