@m144 said in Windows desktop shortcuts... .ico images gone after sysprep!:
@avaryan WOW that was quick… Did you just make this!
Modified from something I previously wrote so that I could apply auto login values in bulk via IP addresses exported from DHCP and saved in a csv file. This was at a time when our DNS records weren’t reliable so the tool that I typical use to set auto login wasn’t working reliably.
The original, in case anyone ever needs it for something:
<#
.Synopsis
Enables Automatic Login with supplied credentials.
.DESCRIPTION
Logs off all users, sets AutoLogon registry keys with entered values, restarts the computer.
.EXAMPLE
./Set-AutoLogon.ps1 -ComputerName PTSD-TestComputer -Username PTSD\TestAccount -Password Password123 -TimesToLogin 3
This will automatically logon to PTSD-TestComputer three times as the TestAccount user. The computer will revert to the normal logon procedure after the third automatic logon.
.NOTES
Supplied credentials are stored in plain text in the registry. They are removed from the registry when the number of
automatic logons is depleted.
#>
Param(
[parameter(Mandatory=$true)]
[String[]]
$ComputerName,
[parameter(Mandatory=$true)]
[String]
$Username,
[parameter(Mandatory=$true)]
[String]
$Password,
[parameter(Mandatory=$false)]
[Int]
$TimesToLogin = 1
)
$credentials = Get-Credential
Invoke-Command -ComputerName $ComputerName -Credential $credentials -ScriptBlock {
Param($Times, $User, $Pass)
$shutdown = $env:SystemRoot + "\System32\shutdown.exe"
Start-Process -FilePath $shutdown -ArgumentList '-l -f' -Wait
Start-Sleep -Seconds 2
$path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
Set-ItemProperty -Path $path -Name AutoAdminLogon -Value 1
Set-ItemProperty -Path $path -Name DefaultUserName -Value $User
if (-Not (Get-ItemProperty -Path $path | Select-Object -ExpandProperty "DefaultPassword" -ErrorAction SilentlyContinue )) {
New-ItemProperty -Path $path -Name DefaultPassword -Value $Pass | Out-Null
}
Set-ItemProperty -Path $path -Name DefaultPassword -Value $Pass | Out-Null
if (-Not (Get-ItemProperty -Path $path | Select-Object -ExpandProperty "AutoLogonCount" -ErrorAction SilentlyContinue )) {
New-ItemProperty -Path $path -Name AutoLogonCount -Value $Times | Out-Null
}
Set-ItemProperty -Path $path -Name AutoLogonCount -Value $Times | Out-Null
Restart-Computer -Force
} -ArgumentList $TimesToLogin,$Username,$Password