I'm trying to get the last windows update date from PowerShell, and I want to save it in a windows variable as text, so I can use it in future statements.
I have tried this method, which can be found in various forums and tutorials. However, it saves it as type Object, and X number of characters cannot be subtracted from it.
(New-Object -com "Microsoft.Update.AutoUpdate").Results|fl
I want to be able to extract certain characters from the text printed after that command, or directly get just the date so I can use it in a text declaration.
Here I explain how you can do it step by step
1 - Access the value you are looking for:
In this way you have created a variable that returns the date of the last installation.
But the content of the variable
lastUpdate
is still of type DateTime and not of type String.2 - To convert it to string you must do the following:
If we check the variable and we will see that it was converted correctly.
Note that
ToString("yyyy/MM/dd")
allows you to specify the format.In conclusion what you are looking for can be done with this line
Returns the string: