Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'sudo' ignores profile scripts? #26

Open
SharakPL opened this issue Jun 3, 2019 · 4 comments
Open

'sudo' ignores profile scripts? #26

SharakPL opened this issue Jun 3, 2019 · 4 comments

Comments

@SharakPL
Copy link

SharakPL commented Jun 3, 2019

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
@daniel-liuzzi
Copy link

daniel-liuzzi commented Jun 22, 2019

This seems to have been the case for quite a while now. -noprofile option was added in e03d8db#diff-5f76b86dab02c0a00ffbf73bf10c19caR17, not sure if intentional, though.

@SharakPL
Copy link
Author

So how should I import my powershell scripts to be able to use it with sudo?

@SharakPL
Copy link
Author

SharakPL commented Jan 27, 2020

$start.arguments = "-noprofile $commandPrefix $cmd`nexit `$lastexitcode"

@lukesampson why does it use -noprofile? Seems to work just fine without it.

@brunovieira97
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants