psutils
psutils copied to clipboard
'sudo' ignores profile scripts?
I have my powershell profile in C:\Users\Username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1. I added some custom functions and aliases there that need admin privileges which I can access without problems while running powershell as administrator and typing MyFunction but on non-elevated powershell sudo MyFunction doesn't even recognize the function name and throws error:
MyFunction : The term 'MyFunction' 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 line:1 char:1
+ MyFunction
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MyFunction:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
This seems to have been the case for quite a while now. -noprofile option was added in https://github.com/lukesampson/psutils/commit/e03d8dbedc58f79ff6ce641cfaebb5ed16a24d19#diff-5f76b86dab02c0a00ffbf73bf10c19caR17, not sure if intentional, though.
So how should I import my powershell scripts to be able to use it with sudo?
https://github.com/lukesampson/psutils/blob/c7116ac143ca81f223e6091d0974f45ac241eb1d/sudo.ps1#L32
@lukesampson why does it use -noprofile? Seems to work just fine without it.
Was going to open an Issue exactly about this. Shouldn't it just use PS Profiles if present? It might delay the command execution, though.