2020-03-24 19:08:37 +01:00
// Copyright (c) Microsoft Corporation.
2018-02-13 18:23:53 +01:00
// Licensed under the MIT License.
2016-07-14 04:27:37 +02:00
#region Using directives
using System ;
using System.Collections.Generic ;
using System.Diagnostics.CodeAnalysis ;
using System.Globalization ;
using System.Management.Automation ;
using Microsoft.Management.Infrastructure.Options ;
#endregion
namespace Microsoft.Management.Infrastructure.CimCmdlets
{
/// <summary>
/// Define Protocol type.
/// </summary>
public enum ProtocolType
{
Default ,
2020-05-29 06:56:33 +02:00
2016-07-14 04:27:37 +02:00
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]
Dcom ,
2020-05-29 06:56:33 +02:00
2016-07-14 04:27:37 +02:00
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]
Wsman
2020-11-21 15:26:44 +01:00
}
2016-07-14 04:27:37 +02:00
/// <summary>
2017-01-16 22:31:14 +01:00
/// The Cmdlet allows the IT Pro to create a CimSessionOptions object that she/he
/// can subsequently use to create one or more CimSession connections. The
/// options object holds the CIM Session information that is less commonly set
/// and used by the IT Pro, and most commonly defaulted.
2016-07-14 04:27:37 +02:00
///
2017-01-16 22:31:14 +01:00
/// The Cmdlet has two parameter sets, one for WMMan options and one for DCOM
/// options. Depending on the arguments the Cmdlet will return an instance of
/// DComSessionOptions or WSManSessionOptions, which derive from
2016-07-14 04:27:37 +02:00
/// CimSessionOptions.
/// </summary>
2020-05-22 21:56:47 +02:00
[Alias("ncso")]
2016-08-24 03:21:31 +02:00
[Cmdlet(VerbsCommon.New, "CimSessionOption", DefaultParameterSetName = ProtocolNameParameterSet, HelpUri = "https://go.microsoft.com/fwlink/?LinkId=227969")]
2016-07-14 04:27:37 +02:00
[OutputType(typeof(CimSessionOptions))]
public sealed class NewCimSessionOptionCommand : CimBaseCommand
{
#region constructor
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
/// <summary>
2020-11-27 09:07:58 +01:00
/// Initializes a new instance of the <see cref="NewCimSessionOptionCommand"/> class.
2016-07-14 04:27:37 +02:00
/// </summary>
public NewCimSessionOptionCommand ( )
: base ( parameters , parameterSets )
{
DebugHelper . WriteLogEx ( ) ;
}
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
#endregion
#region cmdlet parameters
/// <summary>
2016-08-26 22:46:03 +02:00
/// The following is the definition of the input parameter "NoEncryption".
2016-07-14 04:27:37 +02:00
/// Switch indicating if WSMan can use no encryption in the given CimSession (there are also global client and server WSMan settings - AllowUnencrypted).
/// </summary>
[Parameter(ParameterSetName = WSManParameterSet)]
public SwitchParameter NoEncryption
{
2021-01-09 08:44:38 +01:00
get
{
return noEncryption ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
noEncryption = value ;
noEncryptionSet = true ;
base . SetParameter ( value , nameNoEncryption ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private SwitchParameter noEncryption ;
private bool noEncryptionSet = false ;
/// <summary>
/// The following is the definition of the input parameter "CertificateCACheck".
2019-01-06 00:40:24 +01:00
/// Switch indicating if Certificate Authority should be validated.
2016-07-14 04:27:37 +02:00
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
public SwitchParameter SkipCACheck
{
2021-01-09 08:44:38 +01:00
get
{
return skipCACheck ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
skipCACheck = value ;
skipCACheckSet = true ;
base . SetParameter ( value , nameSkipCACheck ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private SwitchParameter skipCACheck ;
private bool skipCACheckSet = false ;
/// <summary>
/// The following is the definition of the input parameter "CertificateCNCheck".
2019-01-06 00:40:24 +01:00
/// Switch indicating if Certificate Name should be validated.
2016-07-14 04:27:37 +02:00
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
public SwitchParameter SkipCNCheck
{
2021-01-09 08:44:38 +01:00
get
{
return skipCNCheck ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
skipCNCheck = value ;
skipCNCheckSet = true ;
base . SetParameter ( value , nameSkipCNCheck ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private SwitchParameter skipCNCheck ;
private bool skipCNCheckSet = false ;
/// <summary>
/// The following is the definition of the input parameter "CertRevocationCheck".
/// Switch indicating if certificate should be revoked.
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
public SwitchParameter SkipRevocationCheck
{
2021-01-09 08:44:38 +01:00
get
{
return skipRevocationCheck ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
skipRevocationCheck = value ;
skipRevocationCheckSet = true ;
base . SetParameter ( value , nameSkipRevocationCheck ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private SwitchParameter skipRevocationCheck ;
private bool skipRevocationCheckSet = false ;
/// <summary>
/// The following is the definition of the input parameter "EncodePortInServicePrincipalName".
2019-01-06 00:40:24 +01:00
/// Switch indicating if to encode Port In Service Principal Name.
2016-07-14 04:27:37 +02:00
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
public SwitchParameter EncodePortInServicePrincipalName
{
2021-01-09 08:44:38 +01:00
get
{
return encodeportinserviceprincipalname ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
encodeportinserviceprincipalname = value ;
encodeportinserviceprincipalnameSet = true ;
base . SetParameter ( value , nameEncodePortInServicePrincipalName ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private SwitchParameter encodeportinserviceprincipalname ;
private bool encodeportinserviceprincipalnameSet = false ;
/// <summary>
/// The following is the definition of the input parameter "Encoding".
2017-01-16 22:31:14 +01:00
/// Defined the message encoding.
/// The allowed encodings are { Default | Utf8 | Utf16 }. The default value
2016-07-14 04:27:37 +02:00
/// should be Utf8.
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
public PacketEncoding Encoding
{
2021-01-09 08:44:38 +01:00
get
{
return encoding ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
encoding = value ;
encodingSet = true ;
base . SetParameter ( value , nameEncoding ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private PacketEncoding encoding ;
private bool encodingSet = false ;
/// <summary>
/// The following is the definition of the input parameter "HttpPrefix".
2017-01-16 22:31:14 +01:00
/// This is the HTTP URL on the server on which the WSMan service is listening.
2016-07-14 04:27:37 +02:00
/// In most cases it is /wsman, which is the default.
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
public Uri HttpPrefix
{
2021-01-09 08:44:38 +01:00
get
{
return httpprefix ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
httpprefix = value ;
base . SetParameter ( value , nameHttpPrefix ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private Uri httpprefix ;
/// <summary>
/// The following is the definition of the input parameter "MaxEnvelopeSizeKB".
/// Sets the limit to the maximum size of the WSMan message envelope.
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
2021-07-28 21:39:14 +02:00
public uint MaxEnvelopeSizeKB
2016-07-14 04:27:37 +02:00
{
2021-01-09 08:44:38 +01:00
get
{
return maxenvelopesizekb ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
maxenvelopesizekb = value ;
maxenvelopesizekbSet = true ;
base . SetParameter ( value , nameMaxEnvelopeSizeKB ) ;
}
}
2018-12-24 07:20:06 +01:00
2021-07-28 21:39:14 +02:00
private uint maxenvelopesizekb ;
2016-07-14 04:27:37 +02:00
private bool maxenvelopesizekbSet = false ;
/// <summary>
/// The following is the definition of the input parameter "ProxyAuthentication".
/// Which proxy authentication types to use: Allowed set is:
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
public PasswordAuthenticationMechanism ProxyAuthentication
{
2021-01-09 08:44:38 +01:00
get
{
return proxyAuthentication ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
proxyAuthentication = value ;
proxyauthenticationSet = true ;
base . SetParameter ( value , nameProxyAuthentication ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private PasswordAuthenticationMechanism proxyAuthentication ;
private bool proxyauthenticationSet = false ;
/// <summary>
/// The following is the definition of the input parameter "ProxyCertificateThumbprint".
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
2019-01-07 19:46:00 +01:00
public string ProxyCertificateThumbprint
2016-07-14 04:27:37 +02:00
{
2021-01-09 08:44:38 +01:00
get
{
return proxycertificatethumbprint ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
proxycertificatethumbprint = value ;
base . SetParameter ( value , nameProxyCertificateThumbprint ) ;
}
}
2018-12-24 07:20:06 +01:00
2019-01-07 19:46:00 +01:00
private string proxycertificatethumbprint ;
2016-07-14 04:27:37 +02:00
/// <summary>
/// The following is the definition of the input parameter "ProxyCredential".
/// Ps Credential used by the proxy server when required by the server.
/// </summary>
[Parameter(ParameterSetName = WSManParameterSet)]
[Credential()]
public PSCredential ProxyCredential
{
2021-01-09 08:44:38 +01:00
get
{
return proxycredential ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
proxycredential = value ;
base . SetParameter ( value , nameProxyCredential ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private PSCredential proxycredential ;
/// <summary>
/// The following is the definition of the input parameter "ProxyType".
/// Which proxy type to use: Valid set is:
/// { InternetExplorer | WinHttp | Auto | None }
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
public ProxyType ProxyType
{
2021-01-09 08:44:38 +01:00
get
{
return proxytype ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
proxytype = value ;
proxytypeSet = true ;
base . SetParameter ( value , nameProxyType ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private ProxyType proxytype ;
private bool proxytypeSet = false ;
/// <summary>
/// The following is the definition of the input parameter "UseSSL".
/// Switch indicating if Secure Sockets Layer connection should be used.
/// </summary>
[ Parameter ( ValueFromPipelineByPropertyName = true ,
ParameterSetName = WSManParameterSet ) ]
public SwitchParameter UseSsl
{
2021-01-09 08:44:38 +01:00
get
{
return usessl ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
usessl = value ;
usesslSet = true ;
base . SetParameter ( value , nameUseSsl ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private SwitchParameter usessl ;
private bool usesslSet = false ;
/// <summary>
/// The following is the definition of the input parameter "Impersonation".
2017-01-16 22:31:14 +01:00
/// Used to select if, and if so what kind of, impersonation should be used.
2016-07-14 04:27:37 +02:00
/// Applies only to the DCOM channel.
/// </summary>
[Parameter(ParameterSetName = DcomParameterSet)]
public ImpersonationType Impersonation
{
2021-01-09 08:44:38 +01:00
get
{
return impersonation ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
impersonation = value ;
impersonationSet = true ;
base . SetParameter ( value , nameImpersonation ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private ImpersonationType impersonation ;
private bool impersonationSet = false ;
/// <summary>
/// The following is the definition of the input parameter "PacketIntegrity".
2017-01-16 22:31:14 +01:00
/// Switch indicating if the package integrity in DCOM connections should be
2016-07-14 04:27:37 +02:00
/// checked/enforced.
/// </summary>
[Parameter(ParameterSetName = DcomParameterSet)]
public SwitchParameter PacketIntegrity
{
2021-01-09 08:44:38 +01:00
get
{
return packetintegrity ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
packetintegrity = value ;
packetintegritySet = true ;
base . SetParameter ( value , namePacketIntegrity ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private SwitchParameter packetintegrity ;
private bool packetintegritySet = false ;
/// <summary>
/// The following is the definition of the input parameter "PacketPrivacy".
2017-01-16 22:31:14 +01:00
/// Switch indicating if packet privacy of the packets in DCOM communications
2016-07-14 04:27:37 +02:00
/// should be checked/enforced.
/// </summary>
[Parameter(ParameterSetName = DcomParameterSet)]
public SwitchParameter PacketPrivacy
{
2021-01-09 08:44:38 +01:00
get
{
return packetprivacy ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
packetprivacy = value ;
packetprivacySet = true ;
base . SetParameter ( value , namePacketPrivacy ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private SwitchParameter packetprivacy ;
private bool packetprivacySet = false ;
/// <summary>
/// The following is the definition of the input parameter "Protocol".
2019-01-06 00:40:24 +01:00
/// Switch indicating if to encode Port In Service Principal Name.
2016-07-14 04:27:37 +02:00
/// </summary>
[ Parameter (
Mandatory = true ,
Position = 0 ,
ValueFromPipelineByPropertyName = true ,
ParameterSetName = ProtocolNameParameterSet ) ]
public ProtocolType Protocol
{
2021-01-09 08:44:38 +01:00
get
{
return protocol ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
set
{
protocol = value ;
base . SetParameter ( value , nameProtocol ) ;
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
private ProtocolType protocol ;
/// <summary>
/// The following is the definition of the input parameter "UICulture".
2019-01-06 00:40:24 +01:00
/// Specifies the UI Culture to use. i.e. en-us, ar-sa.
2016-07-14 04:27:37 +02:00
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true)]
2020-11-24 11:44:09 +01:00
public CultureInfo UICulture { get ; set ; }
2016-07-14 04:27:37 +02:00
/// <summary>
/// The following is the definition of the input parameter "Culture".
2019-01-06 00:40:24 +01:00
/// Specifies the culture to use. i.e. en-us, ar-sa.
2016-07-14 04:27:37 +02:00
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true)]
2020-11-24 11:44:09 +01:00
public CultureInfo Culture { get ; set ; }
2016-07-14 04:27:37 +02:00
#endregion
#region cmdlet processing methods
/// <summary>
/// BeginProcessing method.
/// </summary>
protected override void BeginProcessing ( )
{
this . CmdletOperation = new CmdletOperationBase ( this ) ;
this . AtBeginProcess = false ;
2019-01-06 02:51:20 +01:00
}
2016-07-14 04:27:37 +02:00
/// <summary>
/// ProcessRecord method.
/// </summary>
protected override void ProcessRecord ( )
{
base . CheckParameterSet ( ) ;
CimSessionOptions options ;
switch ( this . ParameterSetName )
{
case WSManParameterSet :
{
options = CreateWSMANSessionOptions ( ) ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
break ;
case DcomParameterSet :
{
options = CreateDComSessionOptions ( ) ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
break ;
case ProtocolNameParameterSet :
switch ( Protocol )
{
case ProtocolType . Dcom :
options = CreateDComSessionOptions ( ) ;
break ;
case ProtocolType . Wsman :
default :
options = CreateWSMANSessionOptions ( ) ;
break ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
break ;
default :
return ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( options ! = null )
{
if ( this . Culture ! = null )
{
options . Culture = this . Culture ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . UICulture ! = null )
{
options . UICulture = this . UICulture ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
this . WriteObject ( options ) ;
}
2019-01-06 02:51:20 +01:00
}
2016-07-14 04:27:37 +02:00
/// <summary>
/// EndProcessing method.
/// </summary>
protected override void EndProcessing ( )
{
2019-01-06 02:51:20 +01:00
}
2016-07-14 04:27:37 +02:00
#endregion
#region helper functions
/// <summary>
2019-01-06 00:40:24 +01:00
/// Create DComSessionOptions.
2016-07-14 04:27:37 +02:00
/// </summary>
/// <returns></returns>
internal DComSessionOptions CreateDComSessionOptions ( )
{
2020-11-21 15:29:44 +01:00
DComSessionOptions dcomoptions = new ( ) ;
2016-07-14 04:27:37 +02:00
if ( this . impersonationSet )
{
dcomoptions . Impersonation = this . Impersonation ;
this . impersonationSet = false ;
}
else
{
dcomoptions . Impersonation = ImpersonationType . Impersonate ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . packetintegritySet )
{
dcomoptions . PacketIntegrity = this . packetintegrity ;
this . packetintegritySet = false ;
}
else
{
dcomoptions . PacketIntegrity = true ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . packetprivacySet )
{
dcomoptions . PacketPrivacy = this . PacketPrivacy ;
this . packetprivacySet = false ;
}
else
{
dcomoptions . PacketPrivacy = true ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
return dcomoptions ;
}
/// <summary>
2019-01-06 00:40:24 +01:00
/// Create WSMANSessionOptions.
2016-07-14 04:27:37 +02:00
/// </summary>
/// <returns></returns>
internal WSManSessionOptions CreateWSMANSessionOptions ( )
{
2020-11-21 15:29:44 +01:00
WSManSessionOptions wsmanoptions = new ( ) ;
2016-07-14 04:27:37 +02:00
if ( this . noEncryptionSet )
{
wsmanoptions . NoEncryption = true ;
this . noEncryptionSet = false ;
}
else
{
wsmanoptions . NoEncryption = false ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . skipCACheckSet )
{
wsmanoptions . CertCACheck = false ;
this . skipCACheckSet = false ;
}
else
{
wsmanoptions . CertCACheck = true ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . skipCNCheckSet )
{
wsmanoptions . CertCNCheck = false ;
this . skipCNCheckSet = false ;
}
else
{
wsmanoptions . CertCNCheck = true ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . skipRevocationCheckSet )
{
wsmanoptions . CertRevocationCheck = false ;
this . skipRevocationCheckSet = false ;
}
else
{
wsmanoptions . CertRevocationCheck = true ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . encodeportinserviceprincipalnameSet )
{
wsmanoptions . EncodePortInServicePrincipalName = this . EncodePortInServicePrincipalName ;
this . encodeportinserviceprincipalnameSet = false ;
}
else
{
wsmanoptions . EncodePortInServicePrincipalName = false ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . encodingSet )
{
wsmanoptions . PacketEncoding = this . Encoding ;
}
else
{
wsmanoptions . PacketEncoding = PacketEncoding . Utf8 ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . HttpPrefix ! = null )
{
wsmanoptions . HttpUrlPrefix = this . HttpPrefix ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . maxenvelopesizekbSet )
{
wsmanoptions . MaxEnvelopeSize = this . MaxEnvelopeSizeKB ;
}
else
{
wsmanoptions . MaxEnvelopeSize = 0 ;
}
2018-12-24 07:20:06 +01:00
2018-12-31 16:44:16 +01:00
if ( ! string . IsNullOrWhiteSpace ( this . ProxyCertificateThumbprint ) )
2016-07-14 04:27:37 +02:00
{
2020-11-21 15:29:44 +01:00
CimCredential credentials = new ( CertificateAuthenticationMechanism . Default , this . ProxyCertificateThumbprint ) ;
2016-07-14 04:27:37 +02:00
wsmanoptions . AddProxyCredentials ( credentials ) ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . proxyauthenticationSet )
{
this . proxyauthenticationSet = false ;
DebugHelper . WriteLogEx ( "create credential" , 1 ) ;
CimCredential credentials = CreateCimCredentials ( this . ProxyCredential , this . ProxyAuthentication , @"New-CimSessionOption" , @"ProxyAuthentication" ) ;
if ( credentials ! = null )
{
try
{
DebugHelper . WriteLogEx ( "Add proxy credential" , 1 ) ;
wsmanoptions . AddProxyCredentials ( credentials ) ;
}
catch ( Exception ex )
{
DebugHelper . WriteLogEx ( ex . ToString ( ) , 1 ) ;
2020-05-22 19:33:36 +02:00
throw ;
2016-07-14 04:27:37 +02:00
}
}
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . proxytypeSet )
{
wsmanoptions . ProxyType = this . ProxyType ;
this . proxytypeSet = false ;
}
else
{
wsmanoptions . ProxyType = Options . ProxyType . WinHttp ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
if ( this . usesslSet )
{
wsmanoptions . UseSsl = this . UseSsl ;
this . usesslSet = false ;
}
else
{
wsmanoptions . UseSsl = false ;
}
2018-12-24 07:20:06 +01:00
2016-07-14 04:27:37 +02:00
wsmanoptions . DestinationPort = 0 ;
return wsmanoptions ;
}
#endregion
#region private members
#region const string of parameter names
internal const string nameNoEncryption = "NoEncryption" ;
internal const string nameSkipCACheck = "SkipCACheck" ;
internal const string nameSkipCNCheck = "SkipCNCheck" ;
internal const string nameSkipRevocationCheck = "SkipRevocationCheck" ;
internal const string nameEncodePortInServicePrincipalName = "EncodePortInServicePrincipalName" ;
internal const string nameEncoding = "Encoding" ;
internal const string nameHttpPrefix = "HttpPrefix" ;
internal const string nameMaxEnvelopeSizeKB = "MaxEnvelopeSizeKB" ;
internal const string nameProxyAuthentication = "ProxyAuthentication" ;
internal const string nameProxyCertificateThumbprint = "ProxyCertificateThumbprint" ;
internal const string nameProxyCredential = "ProxyCredential" ;
internal const string nameProxyType = "ProxyType" ;
internal const string nameUseSsl = "UseSsl" ;
internal const string nameImpersonation = "Impersonation" ;
internal const string namePacketIntegrity = "PacketIntegrity" ;
internal const string namePacketPrivacy = "PacketPrivacy" ;
internal const string nameProtocol = "Protocol" ;
#endregion
/// <summary>
2019-01-09 22:07:41 +01:00
/// Static parameter definition entries.
2016-07-14 04:27:37 +02:00
/// </summary>
2020-11-21 15:29:44 +01:00
private static readonly Dictionary < string , HashSet < ParameterDefinitionEntry > > parameters = new ( )
2016-07-14 04:27:37 +02:00
{
{
nameNoEncryption , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
{
nameSkipCACheck , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
{
nameSkipCNCheck , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
{
nameSkipRevocationCheck , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
{
nameEncodePortInServicePrincipalName , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
{
nameEncoding , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
{
nameHttpPrefix , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
{
nameMaxEnvelopeSizeKB , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
{
nameProxyAuthentication , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
{
nameProxyCertificateThumbprint , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
{
nameProxyCredential , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
{
nameProxyType , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
{
nameUseSsl , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . WSManParameterSet , false ) ,
}
} ,
{
nameImpersonation , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . DcomParameterSet , false ) ,
}
} ,
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
{
namePacketIntegrity , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . DcomParameterSet , false ) ,
}
} ,
{
namePacketPrivacy , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . DcomParameterSet , false ) ,
}
} ,
2017-01-16 22:31:14 +01:00
2016-07-14 04:27:37 +02:00
{
nameProtocol , new HashSet < ParameterDefinitionEntry > {
new ParameterDefinitionEntry ( CimBaseCommand . ProtocolNameParameterSet , true ) ,
}
} ,
} ;
/// <summary>
2019-01-09 22:07:41 +01:00
/// Static parameter set entries.
2016-07-14 04:27:37 +02:00
/// </summary>
2020-11-21 15:29:44 +01:00
private static readonly Dictionary < string , ParameterSetEntry > parameterSets = new ( )
2016-07-14 04:27:37 +02:00
{
{ CimBaseCommand . ProtocolNameParameterSet , new ParameterSetEntry ( 1 , true ) } ,
{ CimBaseCommand . DcomParameterSet , new ParameterSetEntry ( 0 ) } ,
{ CimBaseCommand . WSManParameterSet , new ParameterSetEntry ( 0 ) } ,
} ;
#endregion
2019-01-06 02:51:20 +01:00
}
}