protected CimSessionProxy CreateSessionProxy(string computerName, CimBaseCommand cmdlet) { CimSessionProxy cimSessionProxy = null; if (!string.IsNullOrEmpty(computerName) && !computerName.Equals("localhost", StringComparison.OrdinalIgnoreCase)) { /* Set on the fly credentials */ System.Management.Automation.PSCredential credential = GetOnTheFlyCredentials(cmdlet); if (credential == null) { cimSessionProxy = base.CreateCimSessionProxy(computerName); } else { CimSessionOptions options = new WSManSessionOptions(); options.AddDestinationCredentials(cmdlet.CreateCimCredentials(credential, PasswordAuthenticationMechanism.Default, "Get-CimIstance", "Authentication")); cimSessionProxy = base.CreateCimSessionProxy(computerName, options); } } else { cimSessionProxy = base.CreateCimSessionProxy(computerName); } this.SetSessionProxyProperties(ref cimSessionProxy, cmdlet); return(cimSessionProxy); }
/// <summary>FIXME: Method SetProxyConfiguration is MISSING DESCRIPTION</summary> /// <param name="proxy">The HTTP Proxy to use.</param> /// <param name="proxyCredential">The HTTP Proxy Credentials</param> /// <param name="proxyUseDefaultCredentials">True if the proxy should use default credentials</param> public void SetProxyConfiguration(System.Uri proxy, System.Management.Automation.PSCredential proxyCredential, bool proxyUseDefaultCredentials) { // set the proxy configuration _webProxy.Address = proxy; _webProxy.BypassProxyOnLocal = false; _webProxy.Credentials = proxyCredential?.GetNetworkCredential(); _webProxy.UseDefaultCredentials = proxyUseDefaultCredentials; _handler.UseProxy = proxy != null; }
public System.Management.Automation.PSCredential GetCredential() { var userName = string.Format(@"{0}\{1}", name, Administrator.UserName); var securePassword = new System.Security.SecureString(); securePassword.AppendString(Administrator.Password); var cred = new System.Management.Automation.PSCredential(userName, securePassword); return(cred); }
public CommandExecutionResult Invoke() { // Format for mock is: command [parameterName parameterValue.ToString() isSwitch]+ string invokeString = this.Command; if (this.Parameters.Keys.Count > 0) { foreach (string key in this.Parameters.Keys) { string encodedVal = this.Parameters[key] == null ? "null" : this.Parameters[key].ToString(); if (this.Parameters[key] is System.Management.Automation.PSCredential) { System.Management.Automation.PSCredential specificType = (System.Management.Automation.PSCredential) this.Parameters[key]; string password = String.Empty; IntPtr valuePtr = IntPtr.Zero; try { valuePtr = Marshal.SecureStringToGlobalAllocUnicode(specificType.Password); password = Marshal.PtrToStringUni(valuePtr); } finally { Marshal.ZeroFreeGlobalAllocUnicode(valuePtr); } encodedVal = "(" + specificType.UserName + " " + password + ")"; } invokeString += String.Format(" [{0} {1}]", key, encodedVal); } } this.runspace.Invoke(invokeString); return(this.MockResult); }
public void TestScriptSettingsParameters(IDictionary <string, object> parameters, string username, string password) { var credential = new System.Management.Automation.PSCredential(username, password.ToSecureString()); parameters.Add(Settings.Parameters.PortalCredentials, credential); }