New to Exchange Management.
Our .NET Web App is hosted in IIS. Our application is interacting with Exchange Server through PowerShell Commands.
We were using Exchange Management Shell 2013 in Windows Server 2012 and currently migrated to Windows Server 2022 and Exchange Management Shell 2019. IIS Application Pool Identity is having permissions to establish the connection.
class ExchangeCmdletHepler { Runspace m_runspace = null; public ExchangeCmdletHepler() { m_runspace = RunspaceFactory.CreateRunspace(); m_runspace.Open(); connectToExchange(); } private void connectToExchange() { Pipeline pipeline = m_runspace.CreatePipeline(); pipeline.Commands.AddScript(". 'C:\Program Files\Microsoft\Exchange Server\V15\Bin\RemoteExchange.ps1'; Connect-ExchangeServer <Exchange Server Here> "); pipeline.Invoke(); } //BAU Functions public String getDLGrpCategoryFromAD(String dlName) { var grpCategoryResp = String.Empty; var cmdText = $"Get-ADGroup \"{dlName}\" | Select GroupCategory"; Command setGrpCmd = new Command(cmdText, true); Pipeline pipeline = m_runspace.CreatePipeline(); pipeline.Commands.Add(setGrpCmd); Collection<PSObject> pipeLineResultList = pipeline.Invoke(); //process pipeLineResultList object; } //Couple of more BAU Functions Goes here.}
After migrating, I can able to connect to the new exchange Server 2019 without any issues. But, when calling the getDLGrpCategoryFromAD() it throws the error as "The term 'Get-ADGroup' is not recognized as the name of a cmdlet, function, script file, or operable program".
Before migration, I could remember that, I used to get the response from the getDLGrpCategoryFromAD() method.
I believe, the connectivity is not persisted after the connectToExchange() scope. Is anything changed from 2013 to 2019? Our code base is pretty much same. Could someone share some inputs/suggestions here. Please correct me if my understanding is wrong.
Thanks.