As we are venturing into the Office 365/SharePoint Online world, there will be the need to run some routine maintenance scripts on schedule. For example, adding a service account as an administrator to OneDrive for Business sites. I have the script to do it, have tested it, it works without issue.

The part I'm stuck on is how to set this up as a scheduled task since it requires connecting to our -my site collection to do it's work. How do people handle the username/password storage in this scenario?

Would this be better to be done as a console application so the username and password is stored and hidden in the compiled executable versus using PowerShell?

2 Answers 2


You can certainly encrypt / decrypt a string with powershell. So, you could have one utility script that's run just to get the password and save it as an encrypted string in a file. When the main script runs, it would read that file and decrypt the string. Instructions for this are here:


And, don't rely on passwords being compiled in the executable! Anyone with Visual Studio who has had 5 minutes of training on how to use the ILDASM.exe tool can read any plain text in the executable, including passwords.


We've decided to use CSOM console applications for these tasks so passwords aren't exposed in plain text scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.