EvotecIT / ADEssentials

PowerShell Active Directory helper functions to manage healthy Active Directory
442 stars 54 forks source link

Test if PowerShell is launched as admin #4

Closed itpro-tips closed 3 years ago

itpro-tips commented 4 years ago

Hi, ADEssentials is very great but I think it could be useful to verify if PowerShell is launched as admin (prevent running or maybe only alert user if it not).

I guess you already know how to to that but if you need.

Because, for some tests, admin context is needed or we get an unexpected and unreal value (for example with Get-WinADDFSHealth). Of course, same think is true with Testimo.

PrzemyslawKlys commented 4 years ago

You should be able to run the test as a user that has permissions on DC, but not on your workstation. Also specifically to Testimo, I don't want to prevent that as some tests will work as a standard users. Get-ADUser/Get-ADComputer and many other tests do not require Domain Admin rights, and even if they require Domain Admin they don't require local admin. It's hard to reliably define test to verify for that.

itpro-tips commented 4 years ago

I understand (and agree) with your point of view, but unfortunately 'run as admin' is often required with some CMDlet. I ran Testimo from DC (never tested from workstation by now) and the CMDlet with issue is Get-CimData -NameSpace "root\microsoftdfs" -Class 'dfsrreplicatedfolderinfo'

I suppose other CMDlet has the same problem, but not very easy to find which one. To be honest, I don't know how to handle this without effort, but I think I can be useful to mention it in a documentation ?

PrzemyslawKlys commented 4 years ago

Sure, if only there would be documentation ;-) You can always help by creating one for each command.