I am trying to run a PowerShell script to connect to multiple filers and do a 'get-ncvol'. I have a scheduled task running from the Windows Task Scheduler that is running with a Group Managed Service Account. My script contains the username that I'm logging into the filer(s) with along with the password which is encrypted in a file (the encryption was done while running with the Group Managed Service Account). I used the following to encrypt the password:
"password" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Set-Content "C:\myfiles\stuff\encryptedpassword.txt"
Then in my script, once again running as my Group Managed Service Account, I do the following:
$username = 'domain\id'
$password = Get-Content "C:\myfiles\stuff\encryptedpassword.txt" | ConvertTo-SecureString
$hosts = Get-Content "C:\myfiles\stuff\filers.txt"
$cred = $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$hosts | % { $filer = $_ Add-NcCredential -controller $filer -credential $cred }
foreach($cluster in $hosts)
{
Connect-NcController -name $cluster | Out-Null
Get-NcVol | Export-CSV $filename -Append -NoTypeInformation
}
When it tries to connect to the filer I get a "
Connect-NcController : Incorrect credentials for myfiler1
I can't figure out why the credential is incorrect.