Subscribe: Posts | Comments
  • Home
  • About Webster
  • Download Scripts
  • Conferences
  • Contact
  • Archives
  • Sitemap
Carl Webster
  • Active Directory
  • Blog
    • Certification
  • PVS
  • Web Interface
    • Receiver
    • Secure Gateway
  • Presentations
  • PowerShell
  • XenApp
    • XenApp 5 for Server 2003
    • XenApp 5 for Server 2008
    • XenApp 6.0
    • XenApp 6.5
  • XenDesktop 5.x
  • XenServer
  • Checking if User has Admin Rights When Running a PowerShell Script

    April 16, 2014

    PowerShell

    For my Active Directory documentation script, if the user requests hardware inventory for the domain controllers, the user must run the script with domain administrator credentials.  How do you determine if a script is being run with Domain Admin rights?


    The following information is taken from:

    Check for Admin Credentials in a PowerShell Script (Scripting Guys blog)

    WindowsPrincipal.IsInRole Method (WindowsBuiltInRole) (MSDN)

    WindowsPrincipal Class (MSDN)

    WindowsPrincipal.IsInRole Method (MSDN)

    WindowsBuiltInRole Enumeration (MSDN)

    For testing if the user is in the LOCAL Administrators group:

    If(([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrators"))
    {
    	#user is a member of local administrators
    }
    Else
    {
    	#user is not a member of local administrators
    }
    

    For testing if the user is in the Domain Admins group:

    If(([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Domain Admins"))
    {
    	#user is a member of domain admins
    }
    Else
    {
    	#user is not a member of domain admins
    }
    

    Hope this helps.

    Webster







    About Carl Webster

    Webster is a Sr. Solutions Architect for Choice Solutions, LLC and specializes in Citrix, Active Directory and Technical Documentation. Webster has been working with Citrix products for many years starting with Multi-User OS/2 in 1990.

    View all posts by Carl Webster →

    Subscribe

    Subscribe to our e-mail newsletter to receive updates.

    Related Posts:

    • Citrix Provisioning Services 7.x Documentation Script Update Version 6.01
    • Citrix Provisioning Services Health Check Script Update Version 1.24
    • Citrix Cloud Documentation Script V1.11
    • Citrix Virtual Apps and Desktops Documentation Script V3.22
    • Citrix XenApp/XenDesktop 7.8+ Documentation Script Update Version 2.39

    Post navigation

    ← XenApp 6 V4.1 Documentation Script Has Been Updated 14-Apr-2014
    Finding Domain Trusts in an Active Directory Forest using Microsoft PowerShell →

    2 Responses to “Checking if User has Admin Rights When Running a PowerShell Script”

    1. Joe Nord Says:
      April 16, 2014 at 11:51 am

      Awesome, and timely! Thanks Webster.

      Reply

    2. Ingmar Verheij Says:
      April 16, 2014 at 8:33 am

      Hi Carl,

      Thanks for sharing this validations, it’s good to know you can check for local and domain administrative priviliges.

      I used the code from Matt Painter to run a PowerShell script with elevated priviliges when it isn’t initially started with it. This might help when running an inventory 🙂
      http://gallery.technet.microsoft.com/scriptcenter/63fd1c0d-da57-4fb4-9645-ea52fc4f1dfb

      Cheers,
      Ingmar

      Reply

    Leave a Reply

    Click here to cancel reply.

Support Script Development

I've spent numerous hours working on the many documentation and miscellaneous scripts, which are freely available, for both personal and commercial use, here on my site.

If you'd like to say thanks, please consider making a donation to keep them going!

Goliath Technologies

Goliath Technologies

DISRUPT 2021 Cloud Workspaces Experience

DISRUPT 2021 Cloud Workspaces Experience

ControlUp Get Virtualization Superpowers

ControlUp Get Virtualization Superpowers

Cost-Effective Application on Any Device

Cost-Effective Application on Any Device

10ZiG

Citrix Technology Professional Fellow

Carl Webster is a Citrix Technology Professional Fellow

vExpert 2020

vExpert 2020

Parallels VIPP

Parallels VIPP

IGEL INSIDER

IGEL INSIDER

Experts Exchange Badge

#1
#2
#3
Questions Answered
Articles Written
Overall Points

Subscribe

Subscribe to our e-mail newsletter to receive updates.

Featured Downloads

  • XenApp 6.5 (139829 downloads)
  • All Scripts Zip File (65531 downloads)
  • XenApp 6 (50200 downloads)
  • Provisioning Services (PVS) Old (40333 downloads)
  • Active Directory (33555 downloads)
  • XenApp 5 for Windows Server 2003 (20607 downloads)
  • XenApp 5 for Windows Server 2008 (19464 downloads)
  • NetScaler Old (ns.conf) (16337 downloads)
  • Active Directory Health Check (15761 downloads)
  • Microsoft DHCP (15208 downloads)
  • Popular
  • Latest
  • Comments
  • Tags
  • Where to Get Copies of the Various Scripts September 30, 2011
  • Citrix XenDesktop 7.6, Provisioning Services 7.6 and the XenDesktop Setup Wizard with Write Cache and Personal vDisk Drives December 24, 2014
  • Citrix XenDesktop 7.1, Provisioning Services 7.1 and the XenDesktop Setup Wizard with Write Cache and Personal vDisk Drives January 28, 2014
  • Documenting a Citrix XenApp 6.5 Farm with Microsoft PowerShell October 7, 2011
  • Changing a Production XenDesktop 7.1 Site to use SQL Mirroring February 11, 2014
  • What Happened to My Managed Service Accounts Container? January 26, 2021
  • Citrix Provisioning Services 7.x Documentation Script Update Version 6.01 January 25, 2021
  • Citrix Provisioning Services Health Check Script Update Version 1.24 January 25, 2021
  • Citrix Cloud Documentation Script V1.11 January 25, 2021
  • Citrix Virtual Apps and Desktops Documentation Script V3.22 January 25, 2021
  • Carl Webster: Almost every script I have is on GitHub. https://...
  • DJ Singh: License information. Dear Carl, Is there any...
  • Carl Webster: I sent you sample reports from my lab. Thanks We...
  • Kenneth Moon: Is there sample Contoso Domain output? I have a cu...
  • Carl Webster: Have you tried the Export and Import options. Thos...
acrobat reader Active Directory adobe certification citrix citrix certification ctx129229 dhcp documentation exams excel How do I how to HP Moonshot learning license license server metaframe moonshot offline servers Personal vDisk powershell PowerShell V2 PowerShell V3 powershell V4 presentation server provisioning services PvD PVS pvs7 pvs 7.1 remoting script scripts server 2012 winframe Word word comobject Word COM Object xenapp xenapp 5 xenapp 6 xenapp 6.5 xendesktop xenserver

Categories

  • Active Directory (91)
  • Blog (91)
  • Certification (5)
  • Citrix Cloud (3)
  • Citrix Federated Authentication Service (4)
  • Citrix Virtual Apps and Desktops (104)
  • Configuration Manager (7)
  • DHCP (17)
  • DNS (21)
  • Hyper-V (1)
  • NetScaler (24)
  • Nutanix (3)
  • Parallels (1)
  • PowerShell (417)
  • Presentations (15)
  • PVS (93)
  • Receiver (3)
  • SCVMM (1)
  • Server 2012 (7)
  • SMS PASSCODE MFA (1)
  • StoreFront (8)
  • Uncategorized (3)
  • Vendor Articles (3)
  • VMware (49)
  • Workspace Environment Management (1)
  • XenApp (48)
  • XenApp 5 for Server 2003 (27)
  • XenApp 5 for Server 2008 (27)
  • XenApp 6.0 (64)
  • XenApp 6.5 (87)
  • XenApp 7.x through CVAD 2006 (5)
  • XenApp/XenDesktop 7.0 – 7.7 (99)
  • XenDesktop 5.x (53)
  • XenMobile (2)
  • XenServer (18)

Recent Posts

  • What Happened to My Managed Service Accounts Container? January 26, 2021
  • Citrix Provisioning Services 7.x Documentation Script Update Version 6.01 January 25, 2021
  • Citrix Provisioning Services Health Check Script Update Version 1.24 January 25, 2021
  • Citrix Cloud Documentation Script V1.11 January 25, 2021
  • Citrix Virtual Apps and Desktops Documentation Script V3.22 January 25, 2021
  • Citrix XenApp/XenDesktop 7.8+ Documentation Script Update Version 2.39 January 25, 2021
  • Citrix XenApp/XenDesktop 7.x Documentation Script Update Version 1.46 January 25, 2021
  • Find Services Using a Domain Account on Specified Computers in Microsoft Active Directory (Get-ServiceAccounts V1.20) January 19, 2021
  • Citrix “Old” Provisioning Services Documentation Script Update 4.30 January 19, 2021
  • Citrix Provisioning Services 7.x Documentation Script Update Version 6.00 January 19, 2021

Copyright © 2003 - 2019 Carl Webster. All Rights Reserved.