-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCCM - Excluded MAC Addresses OSD V2 - CSV.ps1
71 lines (58 loc) · 2.97 KB
/
SCCM - Excluded MAC Addresses OSD V2 - CSV.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
<#
.NOTES
===========================================================================
Created on: 2022-04-27
Created by: Brian Thorp
===========================================================================
.Description
This takes a list of MAC addresses and adds them to SCCM's ignore list.
Typically this is for things like USB dongles or docks used to image machines
(OSD). Contains code from
https://www.prajwaldesai.com/manage-sccm-duplicate-hardware-identifiers/
Now uses a CSV File!
#>
##############################################################################>
# CSV File needs to be structed as follows
# MAC Address | Model | Owner
$CSV = "Import-CSV C:\Temp\USB Ethernet Adapters.csv"
$MACAddresses = $CSV."MAC Address"
# =============================================================================
# Import Modules
# =============================================================================
# -----------------------------------------------------------------------------
# Active Directory
# -----------------------------------------------------------------------------
Import-Module ActiveDirectory -Cmdlet New-ADGroup, Add-ADGroupMember, Get-ADDomain
# -----------------------------------------------------------------------------
# SCCM (Requires Console Installed on machine)
# -----------------------------------------------------------------------------
Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" -ErrorAction SilentlyContinue
# =============================================================================
# Connect to SCCM
# =============================================================================
# Grab the site server information
$SiteInfo = Get-PSDrive -PSProvider CmSite
# Site Code
$SiteCode = $SiteInfo.Name
# FQDN of Site Server
$SiteServer = $SiteInfo.Root
# =============================================================================
# Connect to AD
# =============================================================================
$DomainName = (Get-AdDomainController).Domain
# =============================================================================
# Add the MAC Addresses to the SCCM List
# =============================================================================
# Load the Common MAC Address Table
$MACTable = Get-CIMInstance -ComputerName $SiteServer -Namespace "root\sms\Site_$SiteCode" -Class "SMS_CommonMacAddresses"
foreach ($MACAddress in $MACAddresses)
{
# Is it already in the list?
$AlreadyExists = $MACAddress -eq ($MACTable.macaddress -Match $MACAddress)
# Add it if we need to
if (-not $AlreadyExists)
{
Write-Host "Adding $MACAddress"
Set-CIMInstance -ComputerName $SiteServer -Namespace "root\sms\Site_$SiteCode" -Class "SMS_CommonMacAddresses" -Argument @{MACAddress=$MACAddress}
}
}