/// <summary> /// Lists the vms matching the specified filter options /// </summary> /// <param name="options">The options to use when querying for vms</param> /// <returns>The vms matching the specified filter options</returns> public IEnumerable <PSVM> ListVMs(ListVMOptions options) { if (options == null) { throw new ArgumentNullException("options"); } string poolName = options.Pool == null ? options.PoolName : options.Pool.Name; // Get the single vm matching the specified name if (!string.IsNullOrEmpty(options.VMName)) { WriteVerbose(string.Format(Resources.GBVM_GetByName, options.VMName, poolName)); using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager()) { IVM vm = poolManager.GetVM(poolName, options.VMName, additionalBehaviors: options.AdditionalBehaviors); PSVM psVM = new PSVM(vm); return(new PSVM[] { psVM }); } } // List vms using the specified filter else { ODATADetailLevel odata = null; string verboseLogString = null; if (!string.IsNullOrEmpty(options.Filter)) { verboseLogString = string.Format(Resources.GBVM_GetByOData, poolName); odata = new ODATADetailLevel(filterClause: options.Filter); } else { verboseLogString = string.Format(Resources.GBVM_NoFilter, poolName); } WriteVerbose(verboseLogString); using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager()) { IEnumerableAsyncExtended <IVM> vms = poolManager.ListVMs(poolName, odata, options.AdditionalBehaviors); Func <IVM, PSVM> mappingFunction = v => { return(new PSVM(v)); }; return(PSAsyncEnumerable <PSVM, IVM> .CreateWithMaxCount( vms, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)))); } } }