Advertisement
Guest User

Untitled

a guest
Apr 7th, 2025
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 2.77 KB | Source Code | 0 0
  1. #=============================================================================================================================
  2. #
  3. # Script Name:  Remediate_local_kioskuser_autologon.ps1
  4. # Description:  Agrega el usuario kioskUser0 al grupo de Usuarios locales del puesto y crea las claves de Autologon necesarias
  5. #
  6. #=============================================================================================================================
  7.  
  8. # Modules
  9. Import-Module Microsoft.Powershell.LocalAccounts
  10.  
  11. # Define Variables
  12. $userName = "kioskUser0"
  13. $password = ConvertTo-SecureString $userName -AsPlainText -Force
  14. $groupName = "Usuarios"
  15. $userDescription = "Usuario Quiosco"
  16.  
  17. class RegKeys {
  18.     [String]$Path
  19.     [String]$Name
  20.     [String]$ExpectedValue
  21. }
  22.  
  23. $AutologonRegKeys = @(
  24.     [RegKeys]@{ Path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon';   Name = 'AutoAdminLogon';    ExpectedValue = "1"}
  25.     [RegKeys]@{ Path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon';   Name = 'DefaultDomainName'; ExpectedValue = "."}
  26.     [RegKeys]@{ Path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon';   Name = 'DefaultUserName';   ExpectedValue = "$($userName)"}
  27.     [RegKeys]@{ Path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon';   Name = 'DefaultPassword';   ExpectedValue = "$($userName)"}
  28. )
  29.  
  30. try {
  31.     # Create user if it doesn't exist
  32.     try {
  33.         Get-LocalUser $userName -EA Stop | Out-Null
  34.         Set-LocalUser -Name $userName -AccountNeverExpires -Description $userDescription -Password $password -PasswordNeverExpires:$true -UserMayChangePassword:$false -EA Continue | Out-Null
  35.         Add-LocalGroupMember -SID S-1-5-32-546 -Member $userName -EA Continue # Miembro de Guests
  36.         Remove-LocalGroupMember -SID S-1-5-32-545 -Member $userName -EA Continue # No sea miembro de Users
  37.         Write-Host "User OK: [$userName] ya estaba creado. Se ha configurado."
  38.     } catch [Microsoft.PowerShell.Commands.UserNotFoundException] {
  39.         New-LocalUser -Name $userName -AccountNeverExpires -Description $userDescription -Password $password -PasswordNeverExpires -UserMayNotChangePassword -EA Stop | Out-Null
  40.         Add-LocalGroupMember -SID S-1-5-32-546 -Member $userName -EA Continue# Miembro de Guests
  41.         Remove-LocalGroupMember -SID S-1-5-32-545 -Member $userName -EA Continue # No sea miembro de Users
  42.         Write-Host "User OK: [$userName] creado"
  43.     }
  44.  
  45.     # Create autologon registry keys
  46.     $AutologonRegKeys.GetEnumerator() | Foreach-Object {
  47.         $path = $_.Path
  48.         $name = $_.Name
  49.         $expectedValue = $_.ExpectedValue
  50.  
  51.         Set-ItemProperty -Path $path -Name $name -Value $expectedValue -Type String -Force -EA Stop
  52.         Write-Host "RegKEY OK: Clave [$path][$name] creada con valor [$expectedValue]"
  53.     }
  54.  
  55.     #Exit 0 for Intune, OK
  56.     Write-Host "OK"
  57.     exit 0
  58. } catch {
  59.     Write-Error $_.Exception.Message
  60.     exit 1
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement