Skip to content

Commit

Permalink
Added GetCimSession method (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichWeinmann authored Mar 7, 2024
1 parent e7be384 commit ae20f48
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions project/dbatools/Connection/ManagementConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,35 @@ public object QueryCimDCOMInstance(PSCredential Credential, string Query, string

#endregion DCOM

#region Shared
/// <summary>
/// Generates a CIM session to the target computer.
/// For use with other commands that expect a CIM session.
/// </summary>
/// <param name="Credential">Credential to use (if present)</param>
/// <returns>A CIM Session to the target computer represented by this connection.</returns>
/// <exception cref="Exception">When no CIM Session is available.</exception>
public CimSession GetCimSession(PSCredential Credential = null)
{
Exception tempError = null;
if ((DisabledConnectionTypes & ManagementConnectionType.CimRM) != ManagementConnectionType.CimRM)
{
try { return GetCimWinRMSession(Credential); }
catch (Exception e) { tempError = e; }
}

if ((DisabledConnectionTypes & ManagementConnectionType.CimDCOM) != ManagementConnectionType.CimDCOM)
{
try { return GetCimDComSession(Credential); }
catch (Exception e) { tempError = e; }
}

if (tempError != null)
throw tempError;
throw new Exception("No supporting connection type is enabled!");
}
#endregion Shared

#endregion CIM Execution

/// <summary>
Expand Down

0 comments on commit ae20f48

Please sign in to comment.