Why does Enter-PSSession give access denied errors but works in a new tab?

0
5
Asked By TechWhiz42 On

I have a function that allows me to enter a remote PowerShell session using encrypted credentials from an XML file. It usually works great, but occasionally I get an access denied error. The strange part is that if I open a new tab and try to connect to the same device, it works fine again. Then later, it might stop working in that tab too, forcing me to open a new one each time. Has anyone experienced something like this? Any ideas on how to fix it?

2 Answers

Answered By ScriptGuru88 On

It might be worth trying to run your script outside of PowerShell ISE. I've noticed that ISE can have some weird quirks that mess with remote sessions sometimes.

Answered By DevSavvy99 On

Could you share your function code? I've run into cases where scope issues in modules can affect how other modules behave, leading to these kinds of errors.

TechWhiz42 -

Here’s the function:

Function Enter-PSSessionAADJ {
param ($computer)
[string] $IP = Get-IPFromSCCM $computer
If ($IP) {
$cred = (Get-EncryptedCredentials)
$Session = New-PSSession -ComputerName $IP -ConfigurationName 'Microsoft.PowerShell' -Credential $cred

Enter-PSSession -Session $Session
}
}

I also set an alias EPS for this function which calls another one to get the device's current IP.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.