Skip to content

Instantly share code, notes, and snippets.

@jewishmoses
Last active October 15, 2021 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jewishmoses/e1ab557ad647f8ea0f3f482b373b7853 to your computer and use it in GitHub Desktop.
Save jewishmoses/e1ab557ad647f8ea0f3f482b373b7853 to your computer and use it in GitHub Desktop.
# Functions
function Change-Status
{
param
(
[string]$Status,
[string]$StatusPath = "$env:HOMEDRIVE\status-nymz.txt"
)
[void] (New-Item -Path $StatusPath -ItemType "file" -Value $Status -Force)
}
function Get-Status
{
$StatusPath = "$env:HOMEDRIVE\status-nymz.txt"
if ([System.IO.File]::Exists($StatusPath))
{
$Status = Get-Content $StatusPath
Return [int]$Status
}
Change-Status 1
Return 1
}
function Automatic-Logon
{
$RegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Set-ItemProperty -Path $RegistryPath -Name DefaultUserName -Value "User"
Set-ItemProperty -Path $RegistryPath -Name DefaultPassword -Value "Password"
Set-ItemProperty -Path $RegistryPath -Name AutoAdminLogon -Value "1"
Set-ItemProperty -Path $RegistryPath -Name ForceAutoLogon -Value "1"
Set-ItemProperty -Path $RegistryPath -Name AutoLogonCount -Value "1"
# If you have joined the computer to a domain, you should add the DefaultDomainName value, and the data for the value should be set as the fully qualified domain name (FQDN) of the domain, for example contoso.com.
}
# Veriables
$ScriptFileName = $MyInvocation.MyCommand.Name
$ScriptCurrentPath = $MyInvocation.MyCommand.Definition
# Make sure script is running as admin
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$RunningAsAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ($RunningAsAdmin -eq 0)
{
Invoke-Item (start powershell ("$ScriptCurrentPath/$ScriptFileName") -Verb runAs
Exit
}
# End
# Credit
Clear-Host
Write-Host -ForegroundColor Yellow @"
# _ _ _ __ __ _
# | \ | (_) ___ | \/ | | |
# | \| |_ _ __ ( _ ) | \ / | ___ ___| |__ ___
# | . ` | | '__| / _ \/\ | |\/| |/ _ \/ __| '_ \ / _ \
# | |\ | | | | (_> < | | | | (_) \__ \ | | | __/
# |_| \_|_|_| \___/\/ |_| |_|\___/|___/_| |_|\___|
#
# Just let the magic happen ;)
#
"@
Start-Sleep -s 5
# End
# Adding script to startup folder
$StartupScriptPath = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\$ScriptFileName"
if ([System.IO.File]::Exists($StartupScriptPath) -eq 0)
{
Copy-Item -Path $ScriptPath -Destination $StartupScriptPath -Force
Change-Status 1
}
# End
$Status = Get-Status
if ($Status -eq 1)
{
Write-Host 1
Change-Status 2
# Automatic-Logon
# Restart-Computer -ComputerName $env:COMPUTERNAME -Force
}
if ($Status -eq 2)
{
Write-Host 2
Change-Status 3
}
if ($Status -eq 3)
{
Write-Host 3
Change-Status 4
}
if ($Status -eq 4)
{
Write-Host 4
Change-Status 5
}
if ($Status -eq 5)
{
Write-Host 5
Remove-Item $StartupScriptPath -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment