Powershell – SecureString in batchjobs / Scheduled Tasks

Powershell – SecureString in batchjobs / Scheduled Tasks

Posted by on 29. J 2023 in Blog

For automation and security purposes, you can create a file with an encrypted password. The encrypted password is only usable with the same user, that creates the file and it has to be on the same machine. So there’s no use in copying the file around and using another user. You could probably also store this string in registry, if you’d like to. I haven’t tried this, though.

Create file with encrypted password:
Read-Host "Enter password" -AsSecureString | ConvertFrom-SecureString | Out-File "C:\IT-Humans\Scriptz\svc_account.txt"

Read file for usage in script:
$sSecureString = Get-Content "C:\IT-Humans\Scriptz\svc_account.txt" | ConvertTo-SecureString