microsoft / CompliancePartnerWorkshops

Scripts and resources to support the Compliance Build-Intent engagements at https://aka.ms/mci/workshops
MIT License
20 stars 17 forks source link

Is local administrator really required to run EngagementPOEReport.ps1? #15

Closed p-harrison closed 6 months ago

p-harrison commented 6 months ago

Most of our users are not local administrators on their machines and have no access to an admin account. I wonder if it's possible to change the script so it can run as a regular user account? I am not a PowerShell guru by any means, but it does not seem like the script does anything that should truly require local admin privileges?

When running it as a regular user we see the following error -

Checking Permissions
get-command : The term 'get-dlpcompliancepolicy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At C:\Users\pharrison\OneDrive - CWSI\Desktop\EngagementPOEReport.ps1:203 char:6
+ if ((get-command get-dlpcompliancepolicy) -and (get-command Get-Organ ...
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (get-dlpcompliancepolicy:String) [Get-Command], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand

At least one needed cmdlet is missing, check account permissions described in the delivery guide and try again.

Strangely if I run Connect-IPPSSession followed by Connect-ExchangeOnline myself the get-dlpcompliancepolicy cmdlet is available.

Thanks for any thoughts!

jimbanach commented 6 months ago

Although recommended just to avoid issues, it should not be required and we do test without running as administrator. Most often we run across an issue like this when there is an old module that is stuck in the local profile and did not upgrade cleanly.

p-harrison commented 6 months ago

Thanks for responding @jimbanach. We experience the same thing on all our Windows machines, so I don't think it's a module updating issue. However having spent (lots!) more time investigating it I am certain it is not related to your Compliance script specifically - essentially if we run Connect-ExchangeOnline or Connect-IPPSSession within a PS1 as a non-admin no modules/functions are available to the script even though the connection is successful (as evidenced by the fact that when the script ends you can use all the imported functions). Very odd!

If you happened to be bored and could cast an eye at a TechCommunity post I created about the issue it would be most appreciated :) - https://techcommunity.microsoft.com/t5/windows-powershell/powershell-cmdlets-not-available-within-a-script-unless-it-is/m-p/4122837#M7974. Or even give somebody in the PS team a prod to take a look maybe.

Cheers