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: Mount A Remote SMB/CIFS/NFS Share as a Specific User

This function is useful in scenarios where a separate user account is needed to mount…

PowerShell: Backup, Archive, and Remove a Microsoft SQL Database

$sqlServer='sqlsherver007' $databaseName="someDatabaseName" $saCredential=get-credential $backupDestination="\\Archive03\MSSQL_Backups" function triggerSqlBackup($sqlServer,$databaseName){ # Ensure the the Jump Box has SQL PowerShell…

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'…