misc.ps1
|
function Disable-WindowsHotkeys { #warning, disables all Windows Hotkeys including Win+R etc. $RegPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" New-ItemProperty -Path $RegPath -Name "NoWinKeys" -Value 1 -PropertyType dword } function Enable-WindowsHotkeys { $RegPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" New-ItemProperty -Path $RegPath -Name "NoWinKeys" -Value 0 -PropertyType dword } function Block-MicrosoftAccounts { <# .SYNOPSIS Prevent users from adding Microsoft accounts (or signing in with -Force) .PARAMETER Force Block signing in with existing Microsoft accounts (Value 3) instead of just preventing new ones (Value 1). WARNING: This may lock you out if no local admin account exists! .PARAMETER ComputerName Run on remote computer(s) #> [CmdletBinding(SupportsShouldProcess)] param( [switch]$Force, [string[]]$ComputerName ) if ($Force) { Write-Warning "Using -Force (Value 3) blocks ALL Microsoft account sign-ins. This may lock you out if no local administrator account exists!" } $ScriptBlock = { param($BlockForce, $WhatIf) $RegPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System" If (-not (Test-Path $RegPath)) { New-Item -Path $RegPath -Force -WhatIf:$WhatIf | Out-Null } $Value = if ($BlockForce) { 3 } else { 1 } New-ItemProperty -Path $RegPath -Name "NoConnectedUser" -Value $Value -PropertyType dword -Force -WhatIf:$WhatIf } if ($ComputerName) { Invoke-Command -ComputerName $ComputerName -ScriptBlock $ScriptBlock -ArgumentList $Force, $WhatIfPreference } else { & $ScriptBlock -BlockForce $Force -WhatIf $WhatIfPreference } } function Unblock-MicrosoftAccounts { <# .SYNOPSIS Allow users to sign in with Microsoft accounts .PARAMETER ComputerName Run on remote computer(s) #> [CmdletBinding(SupportsShouldProcess)] param( [string[]]$ComputerName ) $ScriptBlock = { param($WhatIf) $RegPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System" If (Test-Path $RegPath) { Remove-ItemProperty -Path $RegPath -Name "NoConnectedUser" -ErrorAction SilentlyContinue -WhatIf:$WhatIf } } if ($ComputerName) { Invoke-Command -ComputerName $ComputerName -ScriptBlock $ScriptBlock -ArgumentList $WhatIfPreference } else { & $ScriptBlock -WhatIf $WhatIfPreference } } |