protected override void ProcessRecord() { FileInfo file = string.IsNullOrEmpty(this.File) ? (FileInfo)null : new FileInfo(this.File); List <CredentialStoreItemImpl> list = new List <CredentialStoreItemImpl>(); ICredentialStore credentialStore = (ICredentialStore)null; try { credentialStore = CredentialStoreFactory.CreateCredentialStore(file); if (this.Password == null) { this.Password = ""; } credentialStore.AddPassword(this.Host, this.User, this.Password.ToCharArray()); list.Add(new CredentialStoreItemImpl(this.Host, this.User, new string(credentialStore.GetPassword(this.Host, this.User)), this.File)); } finally { if (credentialStore != null) { credentialStore.Close(); } } this.WriteObject((object)list, true); }
protected override void ProcessRecord() { FileInfo file = string.IsNullOrEmpty(this.File) ? (FileInfo)null : new FileInfo(this.File); string str1 = string.IsNullOrEmpty(this.Host) ? "*" : this.Host; WildcardPattern hostPattern = new WildcardPattern(str1, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); string str2 = string.IsNullOrEmpty(this.User) ? "*" : this.User; WildcardPattern usernamePattern = new WildcardPattern(str2, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); List <CredentialStoreItem> list = new List <CredentialStoreItem>(); try { ICredentialStore credentialStore = (ICredentialStore)null; try { credentialStore = CredentialStoreFactory.CreateCredentialStore(file); foreach (string str3 in credentialStore.GetHosts()) { if (hostPattern.IsMatch(str3)) { foreach (string str4 in credentialStore.GetUsernames(str3)) { if (usernamePattern.IsMatch(str4)) { string password = new string(credentialStore.GetPassword(str3, str4)); list.Add((CredentialStoreItem) new CredentialStoreItemImpl(str3, str4, password, this.File)); } } } } } finally { if (credentialStore != null) { credentialStore.Close(); } } } catch (Exception ex) { this.ThrowTerminatingError(new ErrorRecord(ex, "Core_GetCredentialStoreItem_ProcessRecordget", System.Management.Automation.ErrorCategory.NotSpecified, (object)null)); } this.WriteObject((object)list, true); this.ReportErrorIfNotFound(str1, str2, hostPattern, usernamePattern, (IEnumerable <CredentialStoreItem>)list); }
protected override void ProcessRecord() { if (this.ParameterSetName == "ByFilters" && string.IsNullOrEmpty(this.Host) && string.IsNullOrEmpty(this.User)) { this.ThrowTerminatingError(VMware.VimAutomation.Sdk.Util10Ps.ErrorHandling.ExceptionHelper.VimExceptionToErrorRecord(VMware.VimAutomation.Sdk.Util10.ErrorHandling.ExceptionHelper.CreateClientSideException("Core_RemoveCredentialStoreItem_ProcessRecord_InvalidArguemnt", VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.ErrorCategory.InvalidArgument, (object)null, (Exception)null, typeof(ViError), VMware.VimAutomation.ViCore.Cmdlets.ResourceHelper.ResourceService, (string)null))); } CredentialStoreItem[] credentialStoreItemArray; if (this.ParameterSetName == "ByCredentialItemObject") { credentialStoreItemArray = this._items; } else if (this.ParameterSetName == "ByFilters") { List <CredentialStoreItemImpl> list = new List <CredentialStoreItemImpl>(); FileInfo file = string.IsNullOrEmpty(this.File) ? (FileInfo)null : new FileInfo(this.File); ICredentialStore credentialStore = (ICredentialStore)null; try { credentialStore = CredentialStoreFactory.CreateCredentialStore(file); WildcardPattern wildcardPattern1 = new WildcardPattern("*", WildcardOptions.Compiled | WildcardOptions.IgnoreCase); if (!string.IsNullOrEmpty(this.Host)) { wildcardPattern1 = new WildcardPattern(this.Host, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); } WildcardPattern wildcardPattern2 = new WildcardPattern("*", WildcardOptions.Compiled); if (!string.IsNullOrEmpty(this.User)) { wildcardPattern2 = new WildcardPattern(this.User, WildcardOptions.Compiled); } foreach (string str1 in credentialStore.GetHosts()) { if (wildcardPattern1.IsMatch(str1)) { foreach (string str2 in credentialStore.GetUsernames(str1)) { if (wildcardPattern2.IsMatch(str2)) { string password = new string(credentialStore.GetPassword(str1, str2)); list.Add(new CredentialStoreItemImpl(str1, str2, password, this.File)); } } } } } finally { if (credentialStore != null) { credentialStore.Close(); } } credentialStoreItemArray = (CredentialStoreItem[])list.ToArray(); } else { credentialStoreItemArray = new CredentialStoreItem[0]; } foreach (CredentialStoreItem credentialStoreItem in credentialStoreItemArray) { if (this.ShouldProcess(string.Format(VMware.VimAutomation.ViCore.Cmdlets.ResourceHelper.ResourceService.GetString("Core_RemoveCredentialStoreItem_ProcessRecord_Action"), (object)credentialStoreItem.Host, (object)credentialStoreItem.User))) { FileInfo file = string.IsNullOrEmpty(credentialStoreItem.File) ? (FileInfo)null : new FileInfo(credentialStoreItem.File); ICredentialStore credentialStore = (ICredentialStore)null; try { credentialStore = CredentialStoreFactory.CreateCredentialStore(file); credentialStore.RemovePassword(credentialStoreItem.Host, credentialStoreItem.User); } finally { if (credentialStore != null) { credentialStore.Close(); } } } } }