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); }
public bool CreateNewUser() { try { cb.connect(); ManagedObjectReference hostLocalAccountManager = cb._connection._sic.accountManager; ManagedObjectReference hostAuthorizationManager = cb._connection._sic.authorizationManager; String userName = GenerateRandomString(); String password = GenerateRandomString(); // Create an user HostAccountSpec hostAccountSpec = new HostAccountSpec(); hostAccountSpec.id = userName; hostAccountSpec.password = password; hostAccountSpec.description = "User Description"; cb._connection._service.CreateUser(hostLocalAccountManager, hostAccountSpec); ManagedObjectReference rootFolder = cb._connection._sic.rootFolder; Permission per = new Permission(); per.group = false; per.principal = userName; per.roleId = -1; per.propagate = true; per.entity = rootFolder; cb._connection._service.SetEntityPermissions(hostAuthorizationManager, rootFolder, new Permission[] { per }); ICredentialStore csObj = CredentialStoreFactory.CreateCredentialStore(); var createUserResult = csObj.AddPassword(GetServerName(), userName, password.ToCharArray()); if (createUserResult) { Console.WriteLine("Successfully created user and populate the " + "credential store"); return(true); } return(false); } finally { cb.disConnect(); } }