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: Restart a Service on All Hyper-V Hosts of a Cluster

$serviceName='vmms' $clusterName='HyperV-cluster001' function restartServiceAllClusterNodes($service='vmms',$clusterName){ function restartService($serviceName){ $waitSeconds=40 $isValidProcess=try{[bool](get-service $serviceName -EA Stop)}catch{$false} if($isValidProcess){ try{ $process=Start-Process -FilePath…

JavaScript: Build a Tic Tac Toe Game (without AI)

Demo: https://blog.kimconnect.com/wp-content/projects/ticTacToeGame.html CSS Code: @import url('https://fonts.googleapis.com/css?family=Merienda');body{ font-family: 'Merienda', cursive; font-weight: bold;}#gameBoard { width: 396px; //…

Linux: How To Use Dig

Checking Name Server(s) kim@kim-linux:~$ dig @8.8.8.8 microsoft.com ; <<>> DiG 9.16.1-Ubuntu <<>> @8.8.8.8 microsoft.com ;…