Skip to content

Commit 5c5274c

Browse files
committed
Update script format
1 parent cb75984 commit 5c5274c

File tree

1 file changed

+20
-36
lines changed

1 file changed

+20
-36
lines changed

TOOL-Set-NetworkLevelAuthentication/Set-NetworkLevelAuthentication.ps1

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
function Set-NetworkLevelAuthentication
2-
{
3-
<#
1+
function Set-NetworkLevelAuthentication {
2+
<#
43
.SYNOPSIS
54
This function will set the NLA setting on a local machine or remote machine
65
@@ -37,7 +36,7 @@
3736
#Requires -Version 3.0
3837
[CmdletBinding()]
3938
PARAM (
40-
[Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName)]
39+
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
4140
[System.String[]]$ComputerName = $env:ComputerName,
4241

4342
[Parameter(Mandatory)]
@@ -47,43 +46,34 @@
4746
[System.Management.Automation.Credential()]
4847
$Credential = [System.Management.Automation.PSCredential]::Empty
4948
)#Param
50-
BEGIN
51-
{
52-
TRY
53-
{
54-
IF (-not (Get-Module -Name CimCmdlets))
55-
{
49+
BEGIN {
50+
TRY {
51+
IF (-not (Get-Module -Name CimCmdlets)) {
5652
Write-Verbose -Message '[BEGIN] Import Module CimCmdlets'
5753
Import-Module CimCmdlets -ErrorAction 'Stop' -ErrorVariable ErrorBeginCimCmdlets
5854
}
5955
}
60-
CATCH
61-
{
62-
IF ($ErrorBeginCimCmdlets)
63-
{
56+
CATCH {
57+
IF ($ErrorBeginCimCmdlets) {
6458
Write-Error -Message "[BEGIN] Can't find CimCmdlets Module"
6559
}
6660
}
6761
}#BEGIN
6862

69-
PROCESS
70-
{
71-
FOREACH ($Computer in $ComputerName)
72-
{
63+
PROCESS {
64+
FOREACH ($Computer in $ComputerName) {
7365
Write-Verbose -message $Computer
74-
TRY
75-
{
66+
TRY {
7667
# Building Splatting for CIM Sessions
7768
Write-Verbose -message "$Computer - CIM/WIM - Building Splatting"
7869
$CIMSessionParams = @{
79-
ComputerName = $Computer
80-
ErrorAction = 'Stop'
70+
ComputerName = $Computer
71+
ErrorAction = 'Stop'
8172
ErrorVariable = 'ProcessError'
8273
}
8374

8475
# Add Credential if specified when calling the function
85-
IF ($PSBoundParameters['Credential'])
86-
{
76+
IF ($PSBoundParameters['Credential']) {
8777
Write-Verbose -message "[PROCESS] $Computer - CIM/WMI - Add Credential Specified"
8878
$CIMSessionParams.credential = $Credential
8979
}
@@ -94,17 +84,15 @@
9484

9585
# CIM/WMI Connection
9686
# WsMAN
97-
IF ((Test-WSMan -ComputerName $Computer -ErrorAction SilentlyContinue).productversion -match 'Stack: 3.0')
98-
{
87+
IF ((Test-WSMan -ComputerName $Computer -ErrorAction SilentlyContinue).productversion -match 'Stack: 3.0') {
9988
Write-Verbose -Message "[PROCESS] $Computer - WSMAN is responsive"
10089
$CimSession = New-CimSession @CIMSessionParams
10190
$CimProtocol = $CimSession.protocol
10291
Write-Verbose -message "[PROCESS] $Computer - [$CimProtocol] CIM SESSION - Opened"
10392
}
10493

10594
# DCOM
106-
ELSE
107-
{
95+
ELSE {
10896
# Trying with DCOM protocol
10997
Write-Verbose -Message "[PROCESS] $Computer - Trying to connect via DCOM protocol"
11098
$CIMSessionParams.SessionOption = New-CimSessionOption -Protocol Dcom
@@ -119,27 +107,23 @@
119107
$NLAinfo | Invoke-CimMethod -MethodName SetUserAuthenticationRequired -Arguments @{ UserAuthenticationRequired = $EnableNLA } -ErrorAction 'Continue' -ErrorVariable ErrorProcessInvokeWmiMethod
120108
}
121109

122-
CATCH
123-
{
110+
CATCH {
124111
Write-Warning -Message "Error on $Computer"
125112
Write-Error -Message $_.Exception.Message
126113
if ($ErrorTestConnection) { Write-Warning -Message "[PROCESS] Error - $ErrorTestConnection" }
127114
if ($ProcessError) { Write-Warning -Message "[PROCESS] Error - $ProcessError" }
128115
if ($ErrorProcessInvokeWmiMethod) { Write-Warning -Message "[PROCESS] Error - $ErrorProcessInvokeWmiMethod" }
129116
}#CATCH
130-
FINALLY
131-
{
132-
if ($CimSession)
133-
{
117+
FINALLY {
118+
if ($CimSession) {
134119
# CLeanup/Close the remaining session
135120
Write-Verbose -Message "[PROCESS] Finally Close any CIM Session(s)"
136121
Remove-CimSession -CimSession $CimSession
137122
}
138123
}
139124
} # FOREACH
140125
}#PROCESS
141-
END
142-
{
126+
END {
143127
Write-Verbose -Message "[END] Script is completed"
144128
}
145129
}

0 commit comments

Comments
 (0)