How it works...

The object that is returned by Get-Date has several methods just like how it has properties. In this recipe, we use the methods to manipulate date the way we need it. Methods are called with arguments. When you do not want to specify any argument, ensure still to call the methods with an empty pair of parentheses.

Methods can be chained in the way we did in adding hours as well as minutes. As long as the output object does not change, in most cases, you should be able to call methods pertaining to the object by chaining them. If, for instance, you convert the date object into string at the first method, the second method should be a string-input-enabled method. When in doubt, use the Get-Member cmdlet on the output to see what methods it would support.

When you look at Get-Member run against the DateTime object, you see that the Subtract method accepts DateTime as its argument. Hence the use of Get-Date within the argument. Passing a cmdlet output as an argument to a method requires the cmdlet, along with the parameters that are passed, to be enclosed within an additional pair of parenthesesSubtract((Get-Date '5 June 2016')) as opposed to Subtract(Get-Date '5 June 2016')so that the inner command is executed first to get a value, and then, passed to the method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.27.178