/// <summary> /// Gets the properties that are bound (set by the user) in the current invocation of this cmdlet. /// </summary> /// <param name="cmdlet">The cmdlet to get the properties from</param> /// <param name="includeInherited">Whether or not to include inherited properties</param> /// <returns>The properties that are bound in the current invocation of this cmdlet.</returns> internal static IEnumerable <PropertyInfo> GetBoundProperties(this PSCmdlet cmdlet, bool includeInherited = true) { // Get the cmdlet's properties IEnumerable <PropertyInfo> cmdletProperties = cmdlet.GetProperties(includeInherited); // Get only the properties that were set from PowerShell IEnumerable <string> boundParameterNames = cmdlet.MyInvocation.BoundParameters.Keys; IEnumerable <PropertyInfo> boundProperties = cmdletProperties.Where(prop => boundParameterNames.Contains(prop.Name) || prop.GetCustomAttribute <AliasAttribute>()?.AliasNames?.Intersect(boundParameterNames)?.Any() == true); return(boundProperties); }