username and password in script

Brass Contributor

Hi,

I want to schedule a ps script to run every 20 minutes.  How to pass username and password securely.

The account is a 0365 account, and the pc where the script is running is not joined to the domain. 

So when running the task  which user account I should use in the task scheduler 

(The purpose the script is to create teams automatically ) 

 

Thanks 

 

 

2 Replies
While creating a task in task scheduler you will have an option to use the user account with which account authentication your task should run in that place you can use your account there, this will work your account has rights to run the tasks on that PC.

Also you can use PS secret management module to include the username and password within the script.
Seeing these are Office 365 credentials, we generally either put them in a file that gets read on the machine or just put them in the script. To increase security, you may also see if the cmdlets you're using support using certificates to connect, but in all cases, there's "something secret" that needs to be stored on the actual system. To prevent issues if that secret is somehow compromised, there's other stuff you can do like only allow this account to be connected to from the machine in question using IP restrictions and Azure AD Conditional Access etc.