@@ -121,7 +121,8 @@ public static void ExecuteSynchronouslyOrAsJob<T>(this T cmdlet, Action<T> execu
121121 throw new ArgumentNullException ( nameof ( executor ) ) ;
122122 }
123123
124- if ( cmdlet . AsJobPresent ( ) )
124+ // Since right now NoWait and AsJob are not in different parameter sets this check is necessary
125+ if ( cmdlet . IsBound ( "AsJob" ) && ! cmdlet . IsBound ( "NoWait" ) )
125126 {
126127 cmdlet . WriteObject ( cmdlet . ExecuteAsJob ( cmdlet . ImplementationBackgroundJobDescription , executor ) ) ;
127128 }
@@ -212,7 +213,7 @@ public static void SafeCopyParameterSet<T>(this T source, T target) where T : Az
212213 /// <returns>true if the parameter was provided by the user, otherwise false</returns>
213214 public static bool IsBound ( this PSCmdlet cmdlet , string parameterName )
214215 {
215- return cmdlet . MyInvocation . BoundParameters . ContainsKey ( parameterName ) ;
216+ return cmdlet . MyInvocation ? . BoundParameters . ContainsKey ( parameterName ) ?? false ;
216217 }
217218
218219 public static string AsAbsoluteLocation ( this string realtivePath )
@@ -358,7 +359,7 @@ public static List<T> ExecuteScript<T>(this PSCmdlet cmdlet, string contents)
358359 public static bool IsParameterBound < TPSCmdlet , TProp > ( this TPSCmdlet cmdlet , Expression < Func < TPSCmdlet , TProp > > propertySelector ) where TPSCmdlet : PSCmdlet
359360 {
360361 var propName = ( ( MemberExpression ) propertySelector . Body ) . Member . Name ;
361- return cmdlet . MyInvocation . BoundParameters . ContainsKey ( propName ) ;
362+ return cmdlet . IsBound ( propName ) ;
362363 }
363364
364365 #region PowerShell Commands
0 commit comments