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: Adding a User to Local Groups

Adding User(s) to Local Groups # addUserToLocalGroup.ps1 # Version 0.02 $computernames=@( 'SERVER0001', 'SERVER0002' ) $accountsToAdd='domain\user1','domain\user2'…

PowerShell: Exchange 2010 Server Update & Restart

function stopExchange{ net stop msexchangeadtopology /y net stop msexchangefba /y net stop msftesql-exchange /y net…

Excel Challenge: Update Records with a New Email Domain if It Matches Deprecated Domain

PrimaryEmail (Cell B2) EmailUsername Domain [email protected] =LEFT(B2,FIND("@",B2)-1) =RIGHT(B2,LEN(B2)-FIND("@",B2)) FixedPrimaryEmail =IF(D2="olddomain.org",C2&"@newdomain.org",B2)