Category: Command Line (Page 2 of 2)

Fixing a windows cloned drive that you need to expand the main partition, but can’t

This video is pretty well perfect for this task:

If you’ve already cloned the drive, but now you’ve got wasted extra space, but you can’t extend the partition because there’s a windows recovery partition in the way. The video linked walks you through it perfectly.

Here’s how you fix that:

command line:

reagentc /disable

diskpart

list partition

select partition x

detail partition

delete partition override

Re-create the Recovery Partition

list partition

select partition x

set id=

gpt attributes=

list volume

select volume y

remove letter=y

exit

reagentc /enable

Note: x=disk or partition number, y=volume letter.

%WINDIR%\system32\sysprep\sysprep.exe

To return to oobe without resetting and rebooting automatically

Return to OOBE without Resetting CMD

Can’t be done remotely

Open CMD as Admin

>Cd sysprep

>sysprep /oobe

To return to oobe and reboot automatically without resetting

Return to OOBE without Resetting CMD

CAN be done remotely (has so far worked with either a saved wifi connection or when connected to ethernet)

Open CMD as Admin

>Cd sysprep

>sysprep /oobe /rebootReturn to OOBE in windows

Powershell Windows Activation

Updated command for Windows 10/11 as of 2/20/26 –

Run Powershell as an administrator, copy and paste the code below and hit enter.  Windows should activate using Option 1 for most Windows OS’s, but use TSForge Option if you need to license a Server install. This can also be used to push through an office install.

NOTE: Only use this at the approval of a supervisor. If we overuse this without the correct licensing as its foundation, we risk a customer being set up for issues in an audit. This command is to be used when Windows fails to activate a license that we know its supposed to activate, often after a Return to OOBE for Entra/Intune Enrollment.

Use the one below for most reliable resolution of get.activated.win in Ultrex Office

iex (curl.exe -s –doh-url https://1.1.1.1/dns-query https://get.activated.win | Out-String)

The following are alternative options if the one above doesn’t work (use your mobile hotspot if needed) –

Option 1:

irm https://get.activated.win | iex

Option 2:

irm https://massgrave.dev/get | iex

If none of the options above work, use this code in powershell administrator mode instead:

if ($ExecutionContext.SessionState.LanguageMode.value__ -ne 0) {
    $ExecutionContext.SessionState.LanguageMode
    Write-Host "Windows PowerShell is not running in Full Language Mode."
    Write-Host "Help - https://massgrave.dev/fix_powershell" -ForegroundColor White -BackgroundColor Blue
    return
}

function Check3rdAV {
    $avList = Get-CimInstance -Namespace root\SecurityCenter2 -Class AntiVirusProduct | Where-Object { $_.displayName -notlike '*windows*' } | Select-Object -ExpandProperty displayName
    if ($avList) {
        Write-Host '3rd party Antivirus might be blocking the script - ' -ForegroundColor White -BackgroundColor Blue -NoNewline
        Write-Host " $($avList -join ', ')" -ForegroundColor DarkRed -BackgroundColor White
    }
}

function CheckFile { 
    param ([string]$FilePath) 
    if (-not (Test-Path $FilePath)) { 
        Check3rdAV
        Write-Host "Failed to create MAS file in temp folder, aborting!"
        Write-Host "Help - https://massgrave.dev/troubleshoot" -ForegroundColor White -BackgroundColor Blue
        throw 
    } 
}

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$URLs = @(
    'https://raw.githubusercontent.com/massgravel/Microsoft-Activation-Scripts/37ec96504a2983a5801c43e975ab78c8f9315d2a/MAS/All-In-One-Version-KL/MAS_AIO.cmd',
    'https://dev.azure.com/massgrave/Microsoft-Activation-Scripts/_apis/git/repositories/Microsoft-Activation-Scripts/items?path=/MAS/All-In-One-Version-KL/MAS_AIO.cmd&versionType=Commit&version=37ec96504a2983a5801c43e975ab78c8f9315d2a',
    'https://git.activated.win/massgrave/Microsoft-Activation-Scripts/raw/commit/37ec96504a2983a5801c43e975ab78c8f9315d2a/MAS/All-In-One-Version-KL/MAS_AIO.cmd'
)

foreach ($URL in $URLs | Sort-Object { Get-Random }) {
    try { $response = Invoke-WebRequest -Uri $URL -UseBasicParsing; break } catch {}
}

if (-not $response) {
    Check3rdAV
    Write-Host "Failed to retrieve MAS from any of the available repositories, aborting!"
    Write-Host "Help - https://massgrave.dev/troubleshoot" -ForegroundColor White -BackgroundColor Blue
    return
}

# Verify script integrity
$releaseHash = '49CE81C583C69AC739890D2DFBB908BDD67B862702DAAEBCD2D38F1DDCEE863D'
$stream = New-Object IO.MemoryStream
$writer = New-Object IO.StreamWriter $stream
$writer.Write($response)
$writer.Flush()
$stream.Position = 0
$hash = [BitConverter]::ToString([Security.Cryptography.SHA256]::Create().ComputeHash($stream)) -replace '-'
if ($hash -ne $releaseHash) {
    Write-Warning "Hash ($hash) mismatch, aborting!`nReport this issue at https://massgrave.dev/troubleshoot"
    $response = $null
    return
}

# Check for AutoRun registry which may create issues with CMD
$paths = "HKCU:\SOFTWARE\Microsoft\Command Processor", "HKLM:\SOFTWARE\Microsoft\Command Processor"
foreach ($path in $paths) { 
    if (Get-ItemProperty -Path $path -Name "Autorun" -ErrorAction SilentlyContinue) { 
        Write-Warning "Autorun registry found, CMD may crash! `nManually copy-paste the below command to fix...`nRemove-ItemProperty -Path '$path' -Name 'Autorun'"
    } 
}

$rand = [Guid]::NewGuid().Guid
$isAdmin = [bool]([Security.Principal.WindowsIdentity]::GetCurrent().Groups -match 'S-1-5-32-544')
$FilePath = if ($isAdmin) { "$env:SystemRoot\Temp\MAS_$rand.cmd" } else { "$env:USERPROFILE\AppData\Local\Temp\MAS_$rand.cmd" }
Set-Content -Path $FilePath -Value "@::: $rand `r`n$response"
CheckFile $FilePath

$env:ComSpec = "$env:SystemRoot\system32\cmd.exe"
Start-Process -FilePath $env:ComSpec -ArgumentList "/c """"$FilePath"" $args""" -Wait
CheckFile $FilePath

$FilePaths = @("$env:SystemRoot\Temp\MAS*.cmd", "$env:USERPROFILE\AppData\Local\Temp\MAS*.cmd")
foreach ($FilePath in $FilePaths) { Get-Item $FilePath | Remove-Item }

Once powershell is successful, a command prompt window will open and give you multiple options.  Select option 1 if you only need the version of  Windows activated.  If you need to change the product type, there should be an option to do so in the same command dialogue box

Domain Joined Device Adding a Local Administrator

New-LocalUser -Name "ADMIN" -Password (ConvertTo-SecureString "ADMIN" -AsPlainText -Force) -UserPrincipalName "ADMIN" -Description "Administrator Account" -AccountNeverExpires $true
Add-LocalGrouMember -Group "Administrators" -Member "ADMIN"
When trying to get administrative access to a domain joined device that is not on the network and does not recognize domain admin credentials and we don't know local admin credentials, through Atera, go to Manage -> PowerShell -> As System and you can either type in "create administrator "ADMIN" with password "ADMIN" or copy and paste the command above.

This process is still in testing until further tests have been ran.

Command Line/Powershell create users, block password change

Add User and Set Password to Never Expire (especially for Scanning User)

Net user Scanning Scanning12 /add

Make PW never expire (Powershell most reliable to work, all will still break with big windows updates)

  • Command Line Admin option 1 (deprecating): WMIC USERACCOUNT where Name=’Scanning’ set PasswordExpires=False
  • Command Line Admin option 2 (sometimes an option): net user “Scanning” /expires:never
  • Powershell Admin (most reliable): Set-LocalUser -Name “Scanning” -PasswordNeverExpires $true

Command line Add Users and Scans Folder w sharing, Password Never Expires

Add User and Set Password to Never Expire (especially for Scanning User)

Net user Scanning Scanning12 /add


Make PW never expire

  • Command Line Admin: WMIC USERACCOUNT where Name=’Scanning’ set PasswordExpires=False
  • Powershell Admin: Set-LocalUser -Name “Scanning” -PasswordNeverExpires $true

Commands to Setup and Share Scans Folder through CLI

Mkdir C:\SCANS (creates Scans folder)

Dir C:\ (to confirm Scans folder creation)

Cd c:\scans (to select scans folder)

Net share scans=c:\scans /grant:Scanning,full (to grant read/write permissions with Scanning User – confirm permissions if needed)

Check Status and Update/Reset Passwords for Multiple Local Users if they’re already a user

Check Expiration Status:

Checking the computer for specified users (Note: must edit the script to check for the usernames you want to check) and what the password expiration status is.

https://app2.atera.com/new/admin/scripts/f63ecf72-e251-4442-bb31-751dcf44c3a6/edit

Password Resets:

Specify and reset multiple users with desired password (NOTE: make sure to edit the username and password before changing).

The script will check if the computer has the specified username, will change the password accordingly if so, and if not will purely skip over the user without making a change.

https://app2.atera.com/new/admin/scripts/00b6aaa1-7653-4662-99d8-dbc3a6d08d7c/edit

Newer posts »

© 2026 Ultrex Staff

Theme by Anders NorenUp ↑