Hi!
I am pretty new to this, but im trying to present when the latest winupdate was done on computer, and only found in powershell to present that, and i tried to run it in C#, but no error and no result.
I understand that im doing wrong, but what is the best way to do this?
I am pretty new to this, but im trying to present when the latest winupdate was done on computer, and only found in powershell to present that, and i tried to run it in C#, but no error and no result.
I understand that im doing wrong, but what is the best way to do this?
C#:
// Get Latest Windows Update
private void LastWinUpd()
{
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
//ps.Commands.AddScript("gwmi win32_quickfixengineering | Select-Object -expandProperty 'installedon' | sort installedon -desc | Select-Object -First 1 | Get-Date -Format 'yyyy - MM - dd K'");
ps.AddCommand("$a = (New - Object - com 'Microsoft.Update.AutoUpdate').Results");
ps.AddCommand("$a.LastInstallationSuccessDate | Get - Date - Format 'yyyy-MM-dd K'");
Collection<PSObject> results = ps.Invoke();
runspace.Close();
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
text_LastWinUpd.Text = obj.ToString();
}
}
// END
Last edited by a moderator: