Is there any way to mock a user with admin privileges?
I have a function that tests to see if a user has admin rights or not
function Test-AdminPrivileges{ $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) }
However, when running invoke-pester it obviously runs as the currently logged in user (i.e. me), which by default is not in the admin group.
I saw over on the Pester wiki that adding a tag to my describe block is one way around this, so I would have to run my testing twice (RequireAdminOnWindows/NonAdminOnWindows), however I’m wondering if there is a way to mock the existence of an admin user without the actual need to enter additional credentials or use the tag method?
I’m fully expecting this to not be possible and that I probably need to get a proper CI pipeline sorted out to run in the individual contexts, but as I haven’t been able to find any answers to this question I thought I would pose it in case someone else comes across the same issue.