当前位置: 首页>>代码示例>>C#>>正文


C# Automation.PSCredential类代码示例

本文整理汇总了C#中System.Management.Automation.PSCredential的典型用法代码示例。如果您正苦于以下问题:C# PSCredential类的具体用法?C# PSCredential怎么用?C# PSCredential使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PSCredential类属于System.Management.Automation命名空间,在下文中一共展示了PSCredential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CimActivityImplementationContext

		public CimActivityImplementationContext(ActivityImplementationContext activityImplementationContext, string computerName, PSCredential credential, string certificateThumbprint, AuthenticationMechanism? authenticationMechanism, bool useSsl, uint port, PSSessionOption sessionOption, CimSession session, CimSessionOptions cimSessionOptions, string moduleDefinition, Uri resourceUri)
		{
			if (activityImplementationContext != null)
			{
				base.PowerShellInstance = activityImplementationContext.PowerShellInstance;
				this.ResourceUri = resourceUri;
				this.ComputerName = computerName;
				base.PSCredential = credential;
				base.PSCertificateThumbprint = certificateThumbprint;
				base.PSAuthentication = authenticationMechanism;
				base.PSUseSsl = new bool?(useSsl);
				base.PSPort = new uint?(port);
				base.PSSessionOption = sessionOption;
				this.Session = session;
				this.SessionOptions = cimSessionOptions;
				if (moduleDefinition != null)
				{
					CimActivityImplementationContext._moduleScriptBlock = ScriptBlock.Create(moduleDefinition);
					this._moduleDefinition = moduleDefinition;
				}
				return;
			}
			else
			{
				throw new ArgumentNullException("activityImplementationContext");
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:27,代码来源:CimActivityImplementationContext.cs

示例2: OnPremisesEncryptString

        public virtual string OnPremisesEncryptString(SecureString value, string resourceGroupName, string dataFactoryName, string gatewayName, PSCredential credential, string type, string nonCredentialValue, string authenticationType)
        {
            LinkedServiceType linkedServiceType = type == null ? LinkedServiceType.OnPremisesSqlLinkedService : (LinkedServiceType)Enum.Parse(typeof(LinkedServiceType), type, true);

            if (linkedServiceType != LinkedServiceType.OnPremisesOdbcLinkedService && (value == null || value.Length == 0))
            {
                throw new ArgumentNullException("value");
            }

            AuthenticationType authType = authenticationType == null ? AuthenticationType.None : (AuthenticationType)Enum.Parse(typeof(AuthenticationType), authenticationType, true);

            var response = DataPipelineManagementClient.Gateways.RetrieveConnectionInfo(resourceGroupName, dataFactoryName, gatewayName);
            var gatewayEncryptionInfos = new[]
                {
                    new GatewayEncryptionInfo
                        {
                            ServiceToken = response.ConnectionInfo.ServiceToken,
                            IdentityCertThumbprint = response.ConnectionInfo.IdentityCertThumbprint,
                            HostServiceUri = response.ConnectionInfo.HostServiceUri,
                            InstanceVersionString = response.ConnectionInfo.Version 
                        }
                };

            string userName = credential != null ? credential.UserName : null;
            SecureString password = credential != null ? credential.Password : null;
            UserInputConnectionString connectionString = new UserInputConnectionString(value, nonCredentialValue, userName, password, linkedServiceType, authType);
            return GatewayEncryptionClient.Encrypt(connectionString, gatewayEncryptionInfos);
        }
开发者ID:pelagos,项目名称:azure-powershell,代码行数:28,代码来源:DataFactoryClient.Encrypt.cs

示例3: Controller

        /// <summary>
        /// Constructor to initialize filed.
        /// </summary>
        /// <param name="conn">Endpoint for VTN-coordinator API.</param>
        /// <param name="credential">Credential to use.</param>
        public Controller(string conn, PSCredential credential)
        {
            if (string.IsNullOrEmpty(conn))
            {
                throw new ArgumentException("connection string empty");
            }

            if (credential == null)
            {
                throw new ArgumentException("No credential provided.");
            }
            if (!conn.StartsWith(@"https://", StringComparison.Ordinal))
            {
                conn = string.Format(CultureInfo.CurrentCulture,
                    @"https://{0}",
                    conn);
            }
            if (conn.EndsWith(@"/", StringComparison.Ordinal))
            {
                conn = conn.Substring(0, conn.Length - 1);
            }
            NetworkCredential cred = new NetworkCredential(credential.UserName,
                    credential.Password);
            this.Base_uri = conn;
            this.Credential = cred;
        }
开发者ID:VamsikrishnaNallabothu,项目名称:vtn,代码行数:31,代码来源:odl.cs

示例4: TestOnPremDatasourceEncryptionWinAuth

        public void TestOnPremDatasourceEncryptionWinAuth()
        {
            SecureString secureString = new SecureString();
            string expectedOutput = "My encrypted string " + Guid.NewGuid();
            string winAuthUserName = "foo";
            SecureString winAuthPassword = new SecureString();
            PSCredential credential = new PSCredential(winAuthUserName, winAuthPassword);
            string linkedServiceType = "OnPremisesFileSystemLinkedService";
            string nonCredentialValue = "Driver=mydriver;server=myserver";
            string authenticationType = "Basic";

            var cmdlet = new NewAzureDataFactoryEncryptValueCommand
            {
                CommandRuntime = this.commandRuntimeMock.Object,
                DataFactoryClient = this.dataFactoriesClientMock.Object,
                Value = secureString,
                ResourceGroupName = ResourceGroupName,
                DataFactoryName = DataFactoryName,
                GatewayName = GatewayName,
                Credential = credential,
                Type = linkedServiceType,
                NonCredentialValue = nonCredentialValue,
                AuthenticationType = authenticationType
            };

            // Arrange
            this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType, nonCredentialValue, authenticationType)).Returns(expectedOutput);

            // Action
            cmdlet.ExecuteCmdlet();

            // Assert
            this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType, nonCredentialValue, authenticationType), Times.Once());
            this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
        }
开发者ID:pelagos,项目名称:azure-powershell,代码行数:35,代码来源:NewDataFactoryEncryptValueTests.cs

示例5: EditValue

 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context == null || context.Instance == null)
     {
         return base.EditValue(context, provider, value);
     }
     else
     {
         value = null;
         NetworkCredential creds = GetCredential();
         if (creds != null)
         {
             System.Security.SecureString pwd = new System.Security.SecureString();
             foreach(var c in creds.Password) 
             {
                 pwd.AppendChar(c);
             }
             PSCredential rtncrds = new PSCredential(creds.UserName, pwd);
             creds = null;
             pwd = null;
             GC.Collect();
             value = rtncrds;
         }
         return value;
     }
 }
开发者ID:x0x029a,项目名称:PoshSecFramework,代码行数:26,代码来源:pscredentialeditor.cs

示例6: Vtn

        /// <summary>
        /// Constructor to initialize fields.
        /// </summary>
        /// <param name="apiEndpoint">Endpoint for ODL API.</param>
        /// <param name="credential">Credential to use.</param>
        public Vtn(string apiEndpoint, PSCredential credential)
        {
            var JavaScriptSerializer = new JavaScriptSerializer();
            JavaScriptSerializer.MaxJsonLength = int.MaxValue;
            StringBuilder json = new StringBuilder("\"apiEndpoint\":" + JavaScriptSerializer.Serialize(apiEndpoint));
            ODLVSEMETW.EventWriteStartODLLibrary(
                MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                json.ToString());
            if (string.IsNullOrEmpty(apiEndpoint)) {
                throw new ArgumentException("No API endpoint specified.");
            }

            if (credential == null) {
                throw new ArgumentException("No credential provided.");
            }

            NetworkCredential cred = new NetworkCredential(credential.UserName,
                credential.Password);
            if (!apiEndpoint.StartsWith(@"https://", StringComparison.Ordinal)) {
                apiEndpoint = string.Format(CultureInfo.CurrentCulture,
                    @"https://{0}",
                    apiEndpoint);
            }
            if (apiEndpoint.EndsWith(@"/", StringComparison.Ordinal)) {
                apiEndpoint = apiEndpoint.Substring(0, apiEndpoint.Length - 1);
            }

            this.ApiEndpoint = apiEndpoint;
            this.Credential = cred;
            ODLVSEMETW.EventWriteEndODLLibrary(
                MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(), string.Empty);
        }
开发者ID:VamsikrishnaNallabothu,项目名称:vtn,代码行数:37,代码来源:Vtn.cs

示例7: SetAzureAutomationCredentialByNameWithParametersSuccessfull

        public void SetAzureAutomationCredentialByNameWithParametersSuccessfull()
        {
            // Setup
            string accountName = "automation";
            string credentialName = "credential";
            string username = "testUser";
            string password = "password";
            string description = "desc";

            var secureString = new SecureString();
            Array.ForEach(password.ToCharArray(), secureString.AppendChar);
            secureString.MakeReadOnly();

            var value = new PSCredential(username, secureString);

            this.mockAutomationClient.Setup(f => f.UpdateCredential(accountName, credentialName, username, password, description));

            // Test
            this.cmdlet.AutomationAccountName = accountName;
            this.cmdlet.Name = credentialName;
            this.cmdlet.Description = description;
            this.cmdlet.Value = value;
            this.cmdlet.ExecuteCmdlet();

            // Assert
            this.mockAutomationClient.Verify(f => f.UpdateCredential(accountName, credentialName, username, password, description), Times.Once());
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:27,代码来源:SetAzureAutomationCredentialTest.cs

示例8: CmdletProviderContext

 internal CmdletProviderContext(CmdletProviderContext contextToCopyFrom)
 {
     this.credentials = PSCredential.Empty;
     this._origin = CommandOrigin.Internal;
     this.accumulatedObjects = new Collection<PSObject>();
     this.accumulatedErrorObjects = new Collection<ErrorRecord>();
     this.stopReferrals = new Collection<CmdletProviderContext>();
     if (contextToCopyFrom == null)
     {
         throw PSTraceSource.NewArgumentNullException("contextToCopyFrom");
     }
     this.executionContext = contextToCopyFrom.ExecutionContext;
     this.command = contextToCopyFrom.command;
     if (contextToCopyFrom.Credential != null)
     {
         this.credentials = contextToCopyFrom.Credential;
     }
     this.drive = contextToCopyFrom.Drive;
     this.force = (bool) contextToCopyFrom.Force;
     this.CopyFilters(contextToCopyFrom);
     this.suppressWildcardExpansion = contextToCopyFrom.SuppressWildcardExpansion;
     this.dynamicParameters = contextToCopyFrom.DynamicParameters;
     this._origin = contextToCopyFrom._origin;
     this.stopping = contextToCopyFrom.Stopping;
     contextToCopyFrom.StopReferrals.Add(this);
     this.copiedContext = contextToCopyFrom;
 }
开发者ID:nickchal,项目名称:pash,代码行数:27,代码来源:CmdletProviderContext.cs

示例9: SetAzureServiceDomainJoinExtensionCmdletInfo

        //Constructor with parameters applicable to all ParameterSets
        private SetAzureServiceDomainJoinExtensionCmdletInfo(DomainJoinExtensionParameterSetType type, string value,
            string[] role, string slot, string serviceName, string thumbprintAlgorithm, bool restart,
            PSCredential credential)
        {
            this.cmdletName = Utilities.SetAzureServiceDomainJoinExtension;

            this.cmdletParams.Add(new CmdletParam(type.ToString(), value));
            if (role != null)
            {
                this.cmdletParams.Add(new CmdletParam("Role", role));
            }
            if (!string.IsNullOrEmpty(slot))
            {
                this.cmdletParams.Add(new CmdletParam("Slot", slot));
            }
            if (!string.IsNullOrEmpty(serviceName))
            {
                this.cmdletParams.Add(new CmdletParam("ServiceName",serviceName));
            }
            if (!string.IsNullOrEmpty(thumbprintAlgorithm))
            {
                this.cmdletParams.Add(new CmdletParam("ThumbprintAlgorithm", thumbprintAlgorithm));
            }
            if (restart)
            {
                this.cmdletParams.Add(new CmdletParam("Restart"));
            }
            if (credential != null)
            {
                this.cmdletParams.Add(new CmdletParam("Credential", credential));
            }
        }
开发者ID:EmmaZhu,项目名称:azure-sdk-tools,代码行数:33,代码来源:SetAzureServiceDomainJoinExtensionCmdletInfo.cs

示例10: UpdatableHelpSystemDrive

 internal UpdatableHelpSystemDrive(PSCmdlet cmdlet, string path, PSCredential credential)
 {
     for (int i = 0; i < 6; i++)
     {
         this._driveName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
         this._cmdlet = cmdlet;
         if (path.EndsWith(@"\", StringComparison.OrdinalIgnoreCase) || path.EndsWith("/", StringComparison.OrdinalIgnoreCase))
         {
             path = path.Remove(path.Length - 1);
         }
         PSDriveInfo atScope = cmdlet.SessionState.Drive.GetAtScope(this._driveName, "local");
         if (atScope != null)
         {
             if (atScope.Root.Equals(path))
             {
                 return;
             }
             if (i < 5)
             {
                 continue;
             }
             cmdlet.SessionState.Drive.Remove(this._driveName, true, "local");
         }
         atScope = new PSDriveInfo(this._driveName, cmdlet.SessionState.Internal.GetSingleProvider("FileSystem"), path, string.Empty, credential);
         cmdlet.SessionState.Drive.New(atScope, "local");
         return;
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:28,代码来源:UpdatableHelpSystemDrive.cs

示例11: OnPremisesEncryptString

        public virtual string OnPremisesEncryptString(SecureString value, string resourceGroupName, string dataFactoryName, string gatewayName, PSCredential credential)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var response = DataPipelineManagementClient.Gateways.RetrieveConnectionInfo(resourceGroupName, dataFactoryName, gatewayName);
            var gatewayEncryptionInfos = new[]
                {
                    new GatewayEncryptionInfo
                        {
                            ServiceToken = response.ConnectionInfo.ServiceToken,
                            IdentityCertThumbprint = response.ConnectionInfo.IdentityCertThumbprint,
                            HostServiceUri = response.ConnectionInfo.HostServiceUri,
                            InstanceVersionString = response.ConnectionInfo.Version 
                        }
                };

            string userName = credential != null ? credential.UserName : null;
            SecureString password = credential != null ? credential.Password : null;
            UserInputConnectionString connectionString = new UserInputConnectionString(value, userName, password);
            var gatewayEncryptionClient = new GatewayEncryptionClient();
            return gatewayEncryptionClient.Encrypt(connectionString, gatewayEncryptionInfos);
        }
开发者ID:nandhanurrevanth,项目名称:azure-powershell,代码行数:25,代码来源:DataFactoryClient.Encrypt.cs

示例12: PSDriveInfo

 public PSDriveInfo(string name, ProviderInfo provider, string root, string description, PSCredential credential)
 {
     this.credentials = PSCredential.Empty;
     if (name == null)
     {
         throw PSTraceSource.NewArgumentNullException("name");
     }
     if (provider == null)
     {
         throw PSTraceSource.NewArgumentNullException("provider");
     }
     if (root == null)
     {
         throw PSTraceSource.NewArgumentNullException("root");
     }
     this.name = name;
     this.provider = provider;
     this.root = root;
     this.description = description;
     if (credential != null)
     {
         this.credentials = credential;
     }
     this.currentWorkingDirectory = string.Empty;
     this.Trace();
 }
开发者ID:nickchal,项目名称:pash,代码行数:26,代码来源:PSDriveInfo.cs

示例13: CompareCredential

		internal static bool CompareCredential(PSCredential credential1, PSCredential credential2)
		{
			if (credential1 != null || credential2 != null)
			{
				if (!(credential1 == null ^ credential2 == null))
				{
					if (string.Compare(credential1.UserName, credential2.UserName, StringComparison.OrdinalIgnoreCase) == 0)
					{
						if (WorkflowUtils.ComparePassword(credential1.Password, credential2.Password))
						{
							return true;
						}
						else
						{
							return false;
						}
					}
					else
					{
						return false;
					}
				}
				else
				{
					return false;
				}
			}
			else
			{
				return true;
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:32,代码来源:WorkflowUtils.cs

示例14: PowerShellProcessInstance

 public PowerShellProcessInstance(Version powerShellVersion, PSCredential credential, ScriptBlock initializationScript, bool useWow64)
 {
     this._syncObject = new object();
     string pSExePath = PSExePath;
     if (useWow64)
     {
         string environmentVariable = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
         if (!string.IsNullOrEmpty(environmentVariable) && (environmentVariable.Equals("amd64", StringComparison.OrdinalIgnoreCase) || environmentVariable.Equals("ia64", StringComparison.OrdinalIgnoreCase)))
         {
             pSExePath = PSExePath.ToLowerInvariant().Replace(@"\system32\", @"\syswow64\");
             if (!System.IO.File.Exists(pSExePath))
             {
                 throw new PSInvalidOperationException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.IPCWowComponentNotPresent, new object[] { pSExePath }));
             }
         }
     }
     string str4 = string.Empty;
     Version version = powerShellVersion ?? PSVersionInfo.PSVersion;
     if (null == version)
     {
         version = new Version(3, 0);
     }
     str4 = string.Format(CultureInfo.InvariantCulture, "-Version {0}", new object[] { new Version(version.Major, version.Minor) });
     str4 = string.Format(CultureInfo.InvariantCulture, "{0} -s -NoLogo -NoProfile", new object[] { str4 });
     if (initializationScript != null)
     {
         string str5 = initializationScript.ToString();
         if (!string.IsNullOrEmpty(str5))
         {
             string str6 = Convert.ToBase64String(Encoding.Unicode.GetBytes(str5));
             str4 = string.Format(CultureInfo.InvariantCulture, "{0} -EncodedCommand {1}", new object[] { str4, str6 });
         }
     }
     ProcessStartInfo info = new ProcessStartInfo {
         FileName = useWow64 ? pSExePath : PSExePath,
         Arguments = str4,
         UseShellExecute = false,
         RedirectStandardInput = true,
         RedirectStandardOutput = true,
         RedirectStandardError = true,
         WindowStyle = ProcessWindowStyle.Hidden,
         CreateNoWindow = true,
         LoadUserProfile = true
     };
     this._startInfo = info;
     if (credential != null)
     {
         NetworkCredential networkCredential = credential.GetNetworkCredential();
         this._startInfo.UserName = networkCredential.UserName;
         this._startInfo.Domain = string.IsNullOrEmpty(networkCredential.Domain) ? "." : networkCredential.Domain;
         this._startInfo.Password = credential.Password;
     }
     System.Diagnostics.Process process = new System.Diagnostics.Process {
         StartInfo = this._startInfo,
         EnableRaisingEvents = true
     };
     this._process = process;
 }
开发者ID:nickchal,项目名称:pash,代码行数:58,代码来源:PowerShellProcessInstance.cs

示例15: NewAzureServiceDomainJoinExtensionConfigCmdletInfo

 // WorkgroupParameterSet
 public NewAzureServiceDomainJoinExtensionConfigCmdletInfo(string workGroupName, X509Certificate2 certificate,string[] role, string thumbprintAlgorithm, bool restart, PSCredential credential)
     : this(role, thumbprintAlgorithm, restart, credential)
 {
     this.cmdletParams.Add(new CmdletParam("WorkGroupName", workGroupName));
     if (certificate != null)
     {
         this.cmdletParams.Add(new CmdletParam("X509Certificate", certificate));
     }
 }
开发者ID:B-Rich,项目名称:azure-sdk-tools,代码行数:10,代码来源:NewAzureServiceDomainJoinExtensionConfigCmdletInfo.cs


注:本文中的System.Management.Automation.PSCredential类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。