HOW TO USE POWERSHELL AS AN ADMIN IN MacOS

%3CLINGO-SUB%20id%3D%22lingo-sub-364123%22%20slang%3D%22en-US%22%3EHOW%20TO%20USE%20POWERSHELL%20AS%20AN%20ADMIN%20IN%20MacOS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-364123%22%20slang%3D%22en-US%22%3E%3CP%3EHowdy%20Folks%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20simple%20query%2C%20being%20fond%20of%20using%20the%20Powershell%20in%20Windows%20Machines%20where%20I%20usually%20run%20the%20commands%20or%20install%20the%20modules%20and%20to%20do%20so%20we%20need%20to%20run%20the%20Windows%20PowerShell%20as%20an%20administrator!!%20But%20the%20same%20option%20is%20not%20available%20in%20MacOS.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThough%20I%20know%20how%20to%20use%20the%20Powershell%20for%20the%20current%20user%20in%20MacOS%20-%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdmitrysotnikov.wordpress.com%2F2016%2F08%2F19%2Frun-powershell-on-mac-os-x%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdmitrysotnikov.wordpress.com%2F2016%2F08%2F19%2Frun-powershell-on-mac-os-x%2F%3C%2FA%3E%20(Steps%20to%20install%20the%20Powershell%20in%20MacOS)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECustomize%20the%20Powershell%20in%20Terminal%20Application%20(%3CA%20href%3D%22https%3A%2F%2Finfo.sapien.com%2Findex.php%2Fquickguides%2Fsetting-up-powershell-on-your-mac%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Finfo.sapien.com%2Findex.php%2Fquickguides%2Fsetting-up-powershell-on-your-mac%3C%2FA%3E)%20also%20done!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20running%20a%20Powershell%20as%20an%20admin%20is%20not%20happening%20in%20MacOS.%20Please%20help%20it%20out%20in%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-364123%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1140042%22%20slang%3D%22en-US%22%3ERe%3A%20HOW%20TO%20USE%20POWERSHELL%20AS%20AN%20ADMIN%20IN%20MacOS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1140042%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F136096%22%20target%3D%22_blank%22%3E%40Mitul%20Sinha%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOk%2C%20had%20the%20same%20problem.%20%22Administrator%22%20in%20Powershell%20does%20not%20mean%20%22Priviledged%20Account%20that%20is%20also%20in%20the%20Admin%20group%22%20in%20OSX%2C%20it%20does%20mean%20%22root%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20have%20to%20%22sudo%20su%20-%20root%22%20to%20switch%20to%20the%20root%20user%20with%20full%20environment%20and%20then%20you%20can%3C%2FP%3E%3CP%3Erun%20pwsh%20and%20Install-Module%20-Scope%20AllUsers%20...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYour%20OSX%20Administrative%20account%20is%20not%20the%20same%20as%20the%20%22Administrator%22%20in%20Powershell%20eyes.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1140068%22%20slang%3D%22en-US%22%3ERe%3A%20HOW%20TO%20USE%20POWERSHELL%20AS%20AN%20ADMIN%20IN%20MacOS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1140068%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F136096%22%20target%3D%22_blank%22%3E%40Mitul%20Sinha%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20need%20to%20run%20pwsh%20under%20the%20login%20and%20environment%20of%20an%20Admin%20user%20(a%20user%20that%20is%20a%20member%20of%20the%20%22admin%22%20UNIX%20group%20in%20OSX).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20verify%20if%20a%20user%20account%20is%20member%20use%20the%20terminal%20command%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20id%20%3CEM%3Eusername%3C%2FEM%3E%3C%2FP%3E%3CP%3Eand%20check%20if%20the%20Group%20%22admin%22%20is%20listed%20(usually%20it%20has%20the%20numerical%20ID%2080)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%20switch%20to%20that%20user%20using%20the%20command%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sudo%20su%20-%20%3CEM%3Eusername%3C%2FEM%3E%3C%2FP%3E%3CP%3E*This%20command%20will%20prompt%20you%20for%20your%20CURRENT%20user's%20password%20if%20you%20are%20allowed%20to%20use%20sudo%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20are%20not%20allowed%20to%20use%20sudo%2C%20use%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20su%20-%20username%3C%2FP%3E%3CP%3Edirectly%2C%20this%20will%20prompt%20for%20the%20password%20of%20the%20user%20you%20want%20to%20switch%20to.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENote%20that%20%22sudo%20su%26nbsp%3B%20-%20root%22%20is%20the%20only%20way%20to%20switch%20to%20the%20root%20account%20(superuser%20admin)%20on%20OSX.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOnce%20you%20switched%20to%20that%20user%20context%2C%20launch%20powershell%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20pwsh%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eand%20install%20any%20module%2Fpackage%20for%20-Scope%20AllUsers%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Echeers%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Frequent Contributor

Howdy Folks,

 

I have a simple query, being fond of using the Powershell in Windows Machines where I usually run the commands or install the modules and to do so we need to run the Windows PowerShell as an administrator!! But the same option is not available in MacOS.

 

Though I know how to use the Powershell for the current user in MacOS - https://dmitrysotnikov.wordpress.com/2016/08/19/run-powershell-on-mac-os-x/ (Steps to install the Powershell in MacOS)

 

Customize the Powershell in Terminal Application (https://info.sapien.com/index.php/quickguides/setting-up-powershell-on-your-mac) also done!

 

But running a Powershell as an admin is not happening in MacOS. Please help it out in this.

 

1 Reply
Highlighted

@Mitul Sinha 

 

You need to run pwsh under the login and environment of an Admin user (a user that is a member of the "admin" UNIX group in OSX).

 

To verify if a user account is member use the terminal command

   id username

and check if the Group "admin" is listed (usually it has the numerical ID 80)

 

Then switch to that user using the command

    sudo su - username

*This command will prompt you for your CURRENT user's password if you are allowed to use sudo

 

If you are not allowed to use sudo, use

    su - username

directly, this will prompt for the password of the user you want to switch to.

 

Note that "sudo su  - root" is the only way to switch to the root account (superuser admin) on OSX.

 

Once you switched to that user context, launch powershell

    pwsh

 

and install any module/package for -Scope AllUsers

 

cheers,