0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
JPPINTO
  • Home
  • Blog
  • Certifications
  • About
  • Contact
  • Shop
  • Gallery
  • Current Setup
Contact

Search

August 18, 2014 / PowerShell

How to check if a Domain User exists using PowerShell without loading AD Snap-Ins

Tags: check user, check user exist, get domain user, get user, powershell
Featured image for How to check if a Domain User exists using PowerShell without loading AD Snap-Ins

I was trying to run “New-SPSite” to create a Site Collection in SharePoint. I accidentally typed in the wrong username as the owner so I received an error. Upon investigation there is not a quick and simple way to see if a user exists outside of SharePoint before its added. Most recommended solutions require you to load an Active Directory Snap-In, which I think is overkill.

In this example I will use the old school NET command for DOS within PowerShell. NET USER is how I used to validate users back in the day when I wrote a lot of batch files.


# set the account to parse
$account = "service-sharepoint"

# we use this in case the account is in the DOMAIN\username format, it will strip out the DOMAIN\ for us
$username =  $account.Split("\") | select -last 1 

# we use the following old school DOS command to get the user info: "net user /domain username"
$checkuser = Start-Process NET -ArgumentList "USER /domain $username" -wait -NoNewWindow -PassThru

# store the exit code in a variable
$value = $checkuser.ExitCode

        # if the user account exists the exit code is 0, no other exit codes should matter
        if ($value -eq 0)
	{
		Write-Host "`r`n Value: `"$value`""
		Write-Host "`r`n Success: User Account: `"$account`" exists on domain. Proceeding." -ForegroundColor Green
		# run your other code here
	}
	else
	{
		Write-Host "`r`n Value: `"$value`""
		Write-Host "`r`n Error: User Account: `"$account`" could not be found. Exiting." -ForegroundColor Red
	}

Post Views: 621
<- How to Install the March 2013 PU and August 2013 CU on SharePoint 2013
Update Enom Domain Name via PowerShell (Dynamic DNS Update) ->

Categories

  • Active Directory (5)
  • AI (3)
  • Amazon Cloud Services (1)
  • AWS (2)
  • Blazor (1)
  • C# (C-Sharp) (3)
  • CI/CD Pipelines (1)
  • Cloud (1)
  • Cloudflare (2)
  • Codex (1)
  • Containers (4)
  • Deployment (2)
  • Development (5)
  • DNS (1)
  • Docker (3)
  • Email (1)
  • Family (1)
  • General (5)
  • IIS 6.0 (4)
  • IIS 7.0 (10)
  • IIS 8.0 (1)
  • Infrastructure as Code (IaC) (1)
  • Kubernetes (3)
  • Linux (9)
  • Microsoft 365 (2)
  • MySQL (1)
  • Office 2010 (1)
  • PHP (1)
  • PowerShell (11)
  • Productivity (1)
  • Security (1)
  • Servers (9)
  • SharePoint 2007 (8)
  • SharePoint 2010 (19)
  • SharePoint 2013 (2)
  • SharePoint Online (1)
  • SMTP (4)
  • SQL Server 2008 (1)
  • SQL Server 2008 R2 (1)
  • SQL Server 2012 (2)
  • SQL Server 2019 (1)
  • SSL (1)
  • Travel (1)
  • Troubleshooting (1)
  • Ubuntu (9)
  • Uncategorized (1)
  • URL Rewrite (2)
  • Visual Studio 2019 (1)
  • Visual Studio Code (1)
  • Windows 10 (7)
  • Windows 2003 (9)
  • Windows 2008 (18)
  • Windows 2012 (6)
  • Windows 7 (3)
  • Windows Firewall (1)
  • Windows Vista (1)
  • WordPress (3)
  • WP-CLI (3)

Recent Posts

  • GPT-5.6 Sol Changes How We Prompt—and How We Write AGENTS.md
  • Protect a Domain That Does Not Send Email with SPF, DMARC, and Null MX
  • Turning Our Atlanta Vacation Photos into a Video with PowerShell
  • Bulk Create Cloudflare Origin CA Certificates with PowerShell
  • Test a Cloudflare Global API Key Connection with PowerShell

Advertisement

Tags

agents.md ai coding agents aws bash cloudflare cloud storage codex context engineering developer workflow dev to production dns externalize blob externalize sharepoint data full installation http redirect https IIS IIS installation index server configuration installing cumulative updates linux load balance central administration microsoft 365 nginx powerpoint powershell redirect http to https s3 server setup sharepoint 2010 cumulative updates sharepoint 2010 farm build sharepoint 2010 farm configuration sharepoint 2010 farm installation sharepoint data externalization SMTP ssl storagepoint ubuntu web server windows Windows 7 windows server 2008 wordpress wp-cli x86
© 2026 JPPinto.com. All rights reserved.