Hello Guys,
As an SCCM administrator, we are receiving the requirement to
deploy applications, patches, application updates post OSD.
Sometimes we have to modify the OS-related settings like if a particular file is present on the machine, then run remediation script OR if a particular
setting is present on the machine, then change it with new settings.
In this scenario, we are going to change the Wireless Adaptor
settings related to Power Management.
Yes, I am talking about Wake on LAN settings WoL. Microsoft
has released Information about power management settings on a network
adapter. Click HERE
to read the Microsoft kb article. This article is important to learn more about
the PnPCapabilities values and how to use its combinations. In this article, MS
provided information on how to use the registry key if we are using this for
broad deployment purposes.
Ok, here we are focusing on the Wireless adaptor and will create a PowerShell script using the above-mentioned settings in the script.
We are using the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\DeviceNumber registry settings to update the wireless settings.
To determine the wireless adaptor Device number We have to
search something like Wi-Fi OR wireless OR If the value is already present in PnPCapabilities,
then we can use PnPCapabilities to search in the registry and the same can be modified
as per requirement.
In the script you can change the -SearchRegex "Wi-Fi" value as per your requirement.
While running the script the log file will be created as a “dcWoL.log”
at
Below is the sample log file output.
In the output file, you can the script is run in three different
scenarios.
1. Single setting is present on the machine and the same has been updated by the script.
2. Wireless adaptor is not found or PnPCapabilities settings are not present on the machine so the script has exited with error “[Error]WoWLAN Settings execution is exiting with return code 0x80070035.”
3. Multiple settings are present on the machine and the same has been updated by the script.
Let's try it yourself and give your valuable feedback on this.
<#
.SYNOPSIS
Update the WoL settings for Wireless
adaptor.
.DESCRIPTION
This script will help you to update the
WoWLAN settings on HP machines.
Reboot is not handled by this PowerShell
script and it's mandatory after execution of this script.
So make sure to changes will take effect
only after rebooting the machine.
.NOTES
=============================================================================================================================================
Created with: Windows PowerShell ISE
Created on: Friday, October 8, 2021 7:28:21 PM
Created by: Dashrath Chate
Organization: Organization Name
=============================================================================================================================================
#>
function find-Reg {
[CmdletBinding()]
param(
[Parameter(Mandatory,
Position=0, ValueFromPipelineByPropertyName)]
[Alias("PsPath")]
[string[]] $Path,
[switch] $Recurse,
[Parameter(ParameterSetName="SingleSearchString",
Mandatory)]
[string] $SearchRegex
)
begin {
switch ($PSCmdlet.ParameterSetName) {
SingleSearchString {
$EmptyValue = -not ($PSBoundParameters.ContainsKey("KeyName") -or $PSBoundParameters.ContainsKey("ValueName") -or $PSBoundParameters.ContainsKey("ValueData"))
if ($KeyName -or $EmptyValue) { $KeyNameRegex = $SearchRegex }
if ($ValueName -or $EmptyValue) { $ValueNameRegex = $SearchRegex }
if ($ValueData -or $EmptyValue) { $ValueDataRegex = $SearchRegex }
}
MultipleSearchStrings {}
}
}
process {
foreach ($CurrentPath in $Path) {
Get-ChildItem $CurrentPath -Recurse:$Recurse |
ForEach-Object {
$Key = $_
if ($KeyNameRegex) {
Write-Verbose ("{0}: Checking KeyNamesRegex" -f $Key.Name)
if ($Key.PSChildName -match $KeyNameRegex) {
Write-Verbose " -> Match
found!"
return [PSCustomObject] @{
Key = $Key
Reason = "KeyName"
}
}
}
if ($ValueNameRegex) {
Write-Verbose ("{0}: Checking ValueNamesRegex" -f $Key.Name)
if ($Key.GetValueNames() -match $ValueNameRegex) {
Write-Verbose " -> Match
found!"
return [PSCustomObject] @{
Key = $Key
Reason = "ValueName"
}
}
}
if ($ValueDataRegex) {
Write-Verbose ("{0}: Checking ValueDataRegex" -f $Key.Name)
if (($Key.GetValueNames() | % { $Key.GetValue($_)
}) -match $ValueDataRegex) {
Write-Verbose " -> Match!"
return [PSCustomObject] @{
Key = $Key
Reason = "ValueData"
}
}
}
}
}
}
}
Add-Type -AssemblyName PresentationFramework
$date
= Get-Date -Format "dd-MM-yyyy
hh:mm:ss"
$log
= "C:\windows\Debug\dcWoL.log"
$Branding = "By Build Admins[Your Company Name]"
Function Writelogfile
{
Param ([string]$logstring)
Add-content $log -value $logstring
}
Function Test-RegPath($regkey, $name) {
$exists = Get-ItemProperty -Path "$regkey" -Name "$name" -ErrorAction SilentlyContinue
If (($exists -ne $null) -and ($exists.Length -ne 0))
{
Return $true
}
Return $false
}
"-----------------------------Script
executed $Branding on $env:COMPUTERNAME at $date (dd-MM-yyyy hh:mm:ss)" + "`r`n" | Out-File $log -append
Write-Progress -Activity "Searching
the WoL settings for Wireless adaptor in $env:COMPUTERNAME."
Writelogfile "$date ----Searching the WoL
settings for Wireless adaptor in $env:COMPUTERNAME. "
$DCKEY = (find-Reg -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}" -Recurse -SearchRegex "Wi-Fi" -ErrorAction SilentlyContinue).key
$SliptDCKey = $DCKEY
$IfExist = $DCKEY
$DataName = "PnPCapabilities"
foreach($SliptDCKey in $SliptDCKey)
{Writelogfile "$date ----WoWLAN Path is $SliptDCKey" + "`r`n"
}
if($DCKEY -ne $null)
{ Writelogfile "$date ----Found the WoL settings for Wireless adaptor in $env:COMPUTERNAME."
Writelogfile "$date ----Updating the WoL setting on $env:COMPUTERNAME."
foreach($IfExist in $IfExist)
{
if((Test-RegPath -regkey registry::$IfExist -name $DataName) -eq $true)
{
foreach($DCKEY in $DCKEY)
{
new-ItemProperty -Path Registry::$DCKEY -Name PnPCapabilities -Value 18 -Force -Confirm:$false
Write-Progress -Activity "Updating the WoL setting on $env:COMPUTERNAME."
Writelogfile "$date ----Updated $DCKEY successfully."
}
}
}
Writelogfile "$date ----WoWLAN Settings execution is exiting with return code 0."
"-----------------------------Script
execution ended on $env:COMPUTERNAME at $date (dd-MM-yyyy hh:mm:ss)" + "`r`n" | Out-File $log -append
}
else
{
Write-Progress -Activity "WoWLAN
Settings[PnPCapabilities] not found on $env:COMPUTERNAME."
Writelogfile "$date ----[Warning]WoWLAN
Settings[PnPCapabilities] not found on $env:COMPUTERNAME."
Writelogfile "$date ----[Error]WoWLAN
Settings execution is exiting with return code 0x80070035."
"-----------------------------Script
execution ended on $env:COMPUTERNAME at $date (dd-MM-yyyy hh:mm:ss)" + "`r`n" | Out-File $log -append
}
No comments:
Post a Comment
Leave your valuable words here for improve better.