I setup a PS script some time ago to login to a remote server and map a drive to a folder in the remote server. This script is currently being used, so I know it works in my environment.
I now need to monitor a folder on the remote server, so I took the appropriate code snippet from my original PS script to use in my folder monitoring script. I can run this new file monitoring script manually without any problems, but when I attempt to schedule it to run from the task scheduler I get the error:
Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "password" is null. Change the value of argument "password" to a non-null value."
I can manually execute each line of code leading up to and including $credential = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password
without any errors. So I'm not quite sure why I can't run the script via the task scheduler, which is how all the other scripts using my connection code are being executed successfully.
When I attempt to display the $password variable after it's populated with password info ($password = Get-Content -Path $psScript\"cpswd.txt" | ConvertTo-SecureString) I get System.Security.SecureString, which I believe is correct.
I have uploaded my script, any guidance is greatly appreciated as I'm stumped at the moment.
