PowerShell / Modules

MIT License
113 stars 25 forks source link

Secret management - secrets and vault can be use in schedule tasks #85

Open harsh26690 opened 4 years ago

harsh26690 commented 4 years ago

Summary of the new feature/enhancement

in Microsoft.PowerShell.SecretManagement, secrets can be use in scripts scheduled.

Proposed technical implementation details (optional)

JustinGrote commented 4 years ago

@harsh26690 I don't have a problem with scheduled tasks, keep in mind though that usually scheduled tasks, unless you specify a different user, run under SYSTEM, so you have to set the secrets as SYSTEM (I usually use psexec to get a system console), because secrets are saved in the Windows Credential Manager which is per-user.

Can you provide more detail to the issue you're facing?

harsh26690 commented 4 years ago

@JustinGrote i need to automate tasks by orchestrator runbook...
command it runs - "%ProgramFiles%"\PowerShell\7\pwsh.exe -Command "& C:\RunBooks\ExchangeTasks\MailboxesPerDatabases\MailboxesPerDB-withsecretmanagement.ps1"

i have saved secret and calling it by $cred=get-secret -name and using this creds to connect Exchange shell session.

Let me know if you want more insides

JustinGrote commented 4 years ago

What account does your sched task run under? Did you run set secret in the same context? You could also try a simpler script to just get-secret and output it to a text file to verify.

harsh26690 commented 4 years ago

@JustinGrote there is no account specify here.. secret saved in cred manager for current user only, so secret set by user A only works for user A. No output I got in text file. Please check some screen shot what i have. secret-powershell-issue.docx

JustinGrote commented 4 years ago

You should use psexec -I -s pwsh to get a SYSTEM account prompt and set the password there. Alternatively, edit your scheduled task to run as the same user you set your secret under.