Getting error while executing PS script in unattended automation

Rohit 0 Reputation points
2023-07-10T12:30:19.0766667+00:00

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.

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,678 questions
Microsoft Exchange
Microsoft Exchange
Microsoft messaging and collaboration software.
567 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,608 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 34,511 Reputation points
    2023-07-10T13:23:19.1966667+00:00

    Sounds like a logon failure. Check the security eventlog on the Exchange server.

    Add a transcript to see if that catches additional error information.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-5.1

    Display the contents of key variables to verify that you have the data that you think you have.

    "The username is {0}" -f $username
    "The botusername is {0}" -f $Botusername
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.