صابر طباطبائی یزدی
صابر طباطبائی یزدی
خواندن ۱ دقیقه·۴ روز پیش

چطوری بفهمم در پاورشل ادمینیستریتور هستم

To check if the current PowerShell session is running with administrative privileges, you can use the following command:

# Check if the PowerShell session is running as administrator if (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host &quotPowerShell is running as administrator.&quot -ForegroundColor Green } else { Write-Host &quotPowerShell is NOT running as administrator.&quot -ForegroundColor Red }

Explanation:

  • [Security.Principal.WindowsIdentity]::GetCurrent() retrieves the current Windows identity.
  • [Security.Principal.WindowsPrincipal] is used to check the roles of the current user.
  • [Security.Principal.WindowsBuiltInRole]::Administrator checks if the current user is in the Administrator role.

Quick Alternative:

To verify manually:

  1. Check the PowerShell window title. If it includes Administrator, the session is running with admin rights.
  2. If a line containing S-1-5-32-544 (Administrators) appears, the session is running as administrator.Run the following command:whoami /groups | findstr "S-1-5-32-544"

What to do if not running as Administrator:

  • Close the current session.
  • Right-click on the PowerShell shortcut and select Run as Administrator.
powershell
برنامه نویس.42ساله. از مدرک MCSD دات نت سال 2002 شروع کردم البته بعد از لیسانس و تمام عمرم رو در مدیریت با ابزار های شیرپوینت و MSPS و CRM و غیره گذراندم.https://zil.ink/sabert
شاید از این پست‌ها خوشتان بیاید