Skip to content

Instantly share code, notes, and snippets.

@gravcat
Created January 2, 2019 18:17
Show Gist options
  • Save gravcat/6b41d068361618872ae5fdb954fed497 to your computer and use it in GitHub Desktop.
Save gravcat/6b41d068361618872ae5fdb954fed497 to your computer and use it in GitHub Desktop.
open a desired tool as another user, such as a domain admin
param (
$domain = $env:USERDOMAIN
)
$ErrorActionPreference = "Stop"
function Get-AdminUsername {
# Admin username determinationator
$user = $env:USERNAME
# create admin_username string based on first char of first name, and first 5 chars of last name
$admin_username = (($env:USERNAME).Substring(0,1) + (($env:USERNAME).Split('.')[1].Substring(0,5)) + "adm" )
return $admin_username # ex: a.superman -> asuper
}
Write-Host -ForegroundColor DarkGreen @"
===== Examples =====
CERTMGR.MSC Certificates snap-in
CERTSRV.MSC - Certification Services
CMD.EXE - Command Prompt
COMPMGMT.MSC - Computer Management
DCPOL.MSC - Domain Controller Security Policy
DFSGUI.MSC - Distributed File System
DHCPMGMT.MSC - DHCP Manager
DISKMGMT.MSC - Disk Management
DNSMGMT.MSC - DNS Manager
DOMAIN.MSC - Active Directory Domains & Trust
DOMPOL.MSC - Domain Security Policy
DSA.MSC - Active Directory Users & Computers
DSA.MSC /DOMAIN=domainname
DSA.MSC /SERVER=servername
DSSITE.MSC - Active Directory Sites & Services
EVENTVWR.MSC - Event Viewer
FSMGMT.MSC - Shared Folders
GPEDIT.MSC - Local Group Policy Editor
IAS.MSC - Internet Authentication Service
INETMGR - Internet Information Service (\Windows\system32\inetsrv)
LUSRMGR.MSC - Local Users and Groups
MMC.EXE - Microsoft Management Console
MSINFO32.EXE - Hardware and software configuration information
PERFMON.MSC - Performance Monitor
REGEDIT.EXE - Run Registry Editor
RRASMGMT.MSC - Routing and Remote Access
RSOP.MSC - Resultant Set of Policy
SECPOL.MSC - Local Security Policy
SERVICES.MSC - Service Configuration
TSCC.MSC - Terminal Services
MSTSC - Remote Desktop
"@
$mmc_open = Read-Host -Prompt "Enter which tool you'd like to open. Default if blank: mmc.exe. Optional args can be included here, separate with spaces as usual. "
if (!$mmc_open) {
$mmc_open = "mmc.exe"
}
try {
$cmd = "runas.exe /user:$domain\$(Get-AdminUsername) ""$mmc_open"""
Start-Process -FilePath "cmd.exe" -ArgumentList "/c","$cmd"
Write-Output "OK, Exiting"
Start-Sleep -Milliseconds 250
Stop-Process -Id $PID
}
catch {
Write-Error "$_.Exception.Message"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment