Search code examples
powershellpowershell-2.0powershell-remoting

Remote script fails when called from another script


I have an odd issue with a script I've created.

It executes various actions on a few different remote hosts. When called directly from the command line it works perfectly. However when the script is invoked from another script (using '&' or '.' operators), it fails for some of the remote machines.

Some of the remote hosts are joined to the same domain as the machine I'm running from, and these hosts fail. Some of the remote hosts are non-domain linked machines and credentials are provided explicitly for them - and in that case they work whether called directly or from a script.

The error is:

The following error occured while using Kerberos authentication: There are currently no logon servers available to service the logon request.

What is the difference between calling the script directly, or from a different script? And how can I work around the issue?


Solution

  • Looks like it was my fault.

    Turns out I was using a variable called $credentials to supply the explicit credentials to the Invoke-Command call. And I was leaving it as null if no explicit credentials were required.

    Unfortunately my calling script was also creating a variable called $credentials to do some of the things it was doing, and the called script had inherited the value from its parent scope - but the new credentials were all wrong for the domain machines and hence the login was failing.

    Bad powershell hacking on my part, thanks all for your help!