Powershell script prompting for credentials when it shouldn’t?

I was working on a simple script to send the status of the built in Windows backup on two 2012r2 servers and one 2008r2 server. I found a script that fitted the bill here  – and on the first two servers it worked fine with the correct details added. However when I tried it on the 2008r2 server I found that I was constantly prompted for credentials – which I assumed were the email details for the server which was to send the emails.

After some thought I checked the versions of powershell and found that the version on the 2008r2 server was a version behind at 2.0 by using the $PSversionTable.psversion command. After updating to the same version I was still presented with the credentials popup – not so good.

I had a thought and commented out the section that I thought was causing  the credentials prompt and realised that through a process of elimination  that the section of the script that might be generating the issue was

Add-PSSnapin Windows.ServerBackup -ErrorAction SilentlyContinue

To test this I issued the Add-PSSnapin Windows.ServerBackup command at the PS prompt and discovered that an error was being given relating to the powershell scripts need to access Windows Backup. Installing the command line windows back tools added the scripts and on the first run the report was delivered. So in this case a different version of powershell and a missing set of scripts lead to a roundabout journey to get to the source of the popup credentials.