Skip to content

Commit ae20f48

Browse files
Added GetCimSession method (#5)
1 parent e7be384 commit ae20f48

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

project/dbatools/Connection/ManagementConnection.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,35 @@ public object QueryCimDCOMInstance(PSCredential Credential, string Query, string
11131113

11141114
#endregion DCOM
11151115

1116+
#region Shared
1117+
/// <summary>
1118+
/// Generates a CIM session to the target computer.
1119+
/// For use with other commands that expect a CIM session.
1120+
/// </summary>
1121+
/// <param name="Credential">Credential to use (if present)</param>
1122+
/// <returns>A CIM Session to the target computer represented by this connection.</returns>
1123+
/// <exception cref="Exception">When no CIM Session is available.</exception>
1124+
public CimSession GetCimSession(PSCredential Credential = null)
1125+
{
1126+
Exception tempError = null;
1127+
if ((DisabledConnectionTypes & ManagementConnectionType.CimRM) != ManagementConnectionType.CimRM)
1128+
{
1129+
try { return GetCimWinRMSession(Credential); }
1130+
catch (Exception e) { tempError = e; }
1131+
}
1132+
1133+
if ((DisabledConnectionTypes & ManagementConnectionType.CimDCOM) != ManagementConnectionType.CimDCOM)
1134+
{
1135+
try { return GetCimDComSession(Credential); }
1136+
catch (Exception e) { tempError = e; }
1137+
}
1138+
1139+
if (tempError != null)
1140+
throw tempError;
1141+
throw new Exception("No supporting connection type is enabled!");
1142+
}
1143+
#endregion Shared
1144+
11161145
#endregion CIM Execution
11171146

11181147
/// <summary>

0 commit comments

Comments
 (0)