Example #1
0
        public override void ExecuteCmdlet()
        {
            CollectionVmsListResult     vmList   = null;
            ActiveDirectoryConfigResult adConfig = null;

            adConfig = CallClient(() => Client.Collections.GetAd(CollectionName), Client.Collections);
            vmList   = CallClient(() => Client.Collections.ListVms(CollectionName), Client.Collections);

            if ((vmList != null) && (vmList.Vms != null) && (adConfig != null) && (adConfig.ActiveDirectoryConfig != null))
            {
                IList <DirectoryEntry> staleEntries = GetVmAdStaleEntries(vmList.Vms, adConfig.ActiveDirectoryConfig, Credential);

                foreach (DirectoryEntry staleEntry in staleEntries)
                {
                    string staleEntryCN         = ActiveDirectoryHelper.GetCN(staleEntry);
                    string shouldProcessMessage = String.Format(Commands_RemoteApp.GenericDeleteConfirmation, staleEntryCN);
                    string verboseDescription   = String.Format(Commands_RemoteApp.GenericDeleteVerboseDescription, staleEntryCN);

                    if (ShouldProcess(verboseDescription, shouldProcessMessage, null))
                    {
                        WriteVerbose(String.Format(Commands_RemoteApp.GenericVerboseDelete, staleEntryCN));
                        ActiveDirectoryHelper.DeleteEntry(staleEntry);
                        WriteObject(staleEntryCN);
                    }
                    else
                    {
                        WriteVerbose(String.Format(Commands_RemoteApp.GenericVerboseSkip, staleEntryCN));
                    }
                }
            }
        }