Our unattended PowerShell script was running successfully since 1 year. There was an issue recently in PROD server and IT team fixed something related to GPO Setting which is now causing failure in our PS script execution.
I've tried logged into PROD server and running same PS script manually and it was working fine but automatic execution causing same reproducible error.
PS Script : This script is authenticating with Exchange Admin On Prem and checking whether user email id is hide from address list or not.
param([Parameter(Mandatory=$true)] $Botusername,[Parameter(Mandatory=$true)] $Password,[Parameter(Mandatory=$true)] $username)
$cred = New-Object System.Management.Automation.PsCredential($Botusername, (ConvertTo-SecureString $Password))
$OnPremSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<Server URI>/PowerShell/ -Authentication Kerberos -Credential $cred
Import-PSSession $OnPremSession
Set-RemoteMailbox -Identity $username -HiddenFromAddressListsEnabled 1
Error : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid value for the argument, and then try running the command again.
Not sure what has changed recently in PROD server and how to fix this type of error.