Morpheus WindowsAgent Powershell Functions - Update

Morpheus Windows Agent Configuration

Powershell Functions for managing the Morpheus Agent config files

This post in an update to my original post on this topic. The functions are now in a Git repo for convenience

The Git Repo is here

The GitHub README has examples on running the Powershell functions including a method to invoke the Powershell fuctions directly from Git into as Dynamic module

Some Examples

Get the Morpheus Windows Agent service status and TCP Socket details

To get the current status of the Morpheus Agent Service along with the associated TCP Socket details returning the output as a json string use

$info = Get-MorpheusAgentSocketStatus -AsJson
$info
{
    "adminAccess":  true,
    "machineName":  "SP54-W-1047",
    "agentStatus":  "OK",
    "agentState":  "Running",
    "apiKey":  "708dbe73-9509-4858-aca5-38f1f276abdb",
    "agentPid":  8104,
    "agentSockets":  {
                         "state":  "Established",
                         "creationTime":  "2023-03-10T17:39:03",
                         "localAddress":  "10.99.23.116",
                         "localPort":  51409,
                         "remoteAddress":  "10.99.23.194",
                         "remotePort":  443
                     }
}

Get the current Agent config file

To See the current Morpheus Windows Agent config file (WindowsAgent.exe.config) use the following function.

Get-MorpheusAgentConfig

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="ServiceName" value="Morpheus Windows Agent" />
    <add key="ApiKey" value="708dbe73-9509-4858-aca5-38f1f276abdb" />
    <add key="Host" value="https://sp-morpheus.mymorpheusappliance.somewhere/" />
    <add key="VmMode" value="true" />
    <add key="LogLevel" value="0" />
    <!-- 0 = debug; 1 = info; 2 = warn; 3 = error; 4 = off;-->
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
</configuration>

Set the Agent Logging Level to 1 (Info) and delay a restart of the Morpheus Windows Agent service

And finally, to set the Morpheus Windows Agent Logging level to Info ($LogLevel=1) , performing a 60 second delayed restart of the Morpheus Windows Agent service use the example below.
$newConfig is the contents of the updated MorpheusAgent.exe.config.
The function has detached a process with pid 4760 which will restart the Morpheus Windows Agent service in 60 seconds.

$newConfig = Set-MorpheusAgentConfig -LogLevel 1 -RestartAgent
Delaying Agent Service Restart - detaching process 4760
Returning Updated Agent Config ...

$newConfig
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="ServiceName" value="Morpheus Windows Agent" />
    <add key="ApiKey" value="708dbe73-9509-4858-aca5-38f1f276abdb" />
    <add key="Host" value="https://sp-morpheus.mymorpheusappliance.somewhere/" />
    <add key="VmMode" value="true" />
    <add key="LogLevel" value="1" />
    <!-- 0 = debug; 1 = info; 2 = warn; 3 = error; 4 = off;-->
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
</configuration>

1 Like