Posted On February 6, 2020

PowerShell: Change Windows Autolock

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Change Windows Autolock
# Disable_AutoLock.ps1

function changeAutoLock{
param (
[Switch]$disable,
[Switch]$enable
)
$registryHive = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization"
$registryKey="NoLockScreen"
$keyItem = Get-ItemProperty -Path $registryHive -Name $registryKey -ErrorAction SilentlyContinue
$keyValue = $keyItem.NoLockScreen

If($enable)
{
If($keyValue){
#Remove item property
Remove-Item -Path $registryHive -Recurse -Confirm:$false | Out-Null
Write-Host "Enabled lock screen successfully."
}Else{
Write-Host "Lock screen has already been enabled prior."
}

}else{
If($keyValue){
Write-Host "Lock screen has already been disabled."
}Else{
New-Item -Path $registryHive -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path $registryHive -Type "DWORD" -Name "NoLockScreen" -Value 1 | Out-Null
Write-Host "Disabled lock screen successfully."
}
}
}

changeAutoLock -disable

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Disable Windows Defender

Simultaneous Uninstalls: # removeWindowsDefender.ps1 # Version 0.02 $computerNames=@( 'server1', 'server2' ) function removeWindowsDefender($computerNames){ function uninstallWindefend($computername){…

Basic CSS: Change the Font Size of an Element

<style>.red-text {color: red;}</style><h2 class="red-text">CatPhotoApp</h2><main><p class="red-text">Click here to view more <a href="#">cat photos</a>.</p><a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A…

PowerShell: Microsoft SQL Administration

Script to Install Microsoft Clustering Service $proxy="http://proxy:8080"$exclusionList="localhost;*.kimconnect.com"function checkProxy{try{$connectionTest=iwr download.microsoft.com#$connectionSucceeds=Test-NetConnection -Computername download.microsoft.com -Port 443 -InformationLevel Quietif…