-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRemediate-NetBiosState.ps1
More file actions
65 lines (61 loc) · 2.69 KB
/
Copy pathRemediate-NetBiosState.ps1
File metadata and controls
65 lines (61 loc) · 2.69 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
<#
.SYNOPSIS
This script checks the state of NetBIOS over TCP/IP on the active network adapter and attempts to disable it if it's not already.
.DESCRIPTION
The script defines two functions, Get-ActiveNetworkCard and Get-NetBiosState.
Get-ActiveNetworkCard retrieves the description of the active network interface card (NIC).
Get-NetBiosState retrieves the current NetBIOS over TCP/IP setting for the active NIC.
The script then checks if NetBIOS is disabled. If it is not, it attempts to disable it and outputs a success message if successful, or an error message if not.
.NOTES
Filename: Remediate-NetBiosState.ps1
Version: 1.0
Author: Martin Bengtsson
Blog: www.imab.dk
Twitter: @mwbengtsson
.EXAMPLE
.\Remediate-NetBiosState.ps1
Checks the state of NetBIOS over TCP/IP on the active network adapter and attempts to disable it if it's not already.
#>
begin {
function Get-ActiveNetworkCard() {
try {
$activeNIC = (Get-NetAdapter | Where-Object {$_.Status -eq "Up" -AND $_.ConnectorPresent -eq $True} | Select-Object InterfaceDescription).InterfaceDescription
} catch {
$activeNIC = $null
}
if (-NOT[string]::IsNullOrEmpty($activeNIC)) {
Write-Output $activeNIC
}
}
function Get-NetBiosState() {
try {
$netBiosOptionStatus = ((Get-CimInstance -ClassName 'Win32_NetworkAdapterConfiguration' -Filter "Description = '$(Get-ActiveNetworkCard)'" | Select-Object -Property @('Description', 'TcpipNetbiosOptions'))).TcpipNetbiosOptions
} catch {
$netBiosOptionStatus = $null
}
switch ($netBiosOptionStatus) {
0 {$netBiosOptionDesc = "EnableNetbiosViaDhcp"}
1 {$netBiosOptionDesc = "EnableNetbios"}
2 {$netBiosOptionDesc = "DisableNetbios"}
}
if (-NOT[string]::IsNullOrEmpty($netBiosOptionStatus)) {
Write-Output $netBiosOptionStatus
Write-Output $netBiosOptionDesc
}
}
}
process {
if ((Get-NetBiosState)[0] -ne 2) {
try {
Get-CimInstance -ClassName 'Win32_NetworkAdapterConfiguration' -Filter "Description = '$(Get-ActiveNetworkCard)'" | Invoke-CimMethod -MethodName SetTcpipNetbios -Arguments @{ TcpipNetbiosOptions = 2 } | Out-Null
Write-Output "[Success] NetBios is now disabled, and is currently configured to: $(Get-NetBiosState)"
exit 0
} catch {
Write-Output "[Error] NetBios was NOT disabled, and is currently configured to: $(Get-NetBiosState)"
exit 1
}
}
}
end {
#Nothing to see here
}