I am trying to create a simple powershell script which will allow it to display the PID and the starttime of a process.
For the moment this is my code -->
$proc=$args[0]
if (get-process -name $proc -ErrorAction SilentlyContinue) {
$time= get-process $proc | Select-Object starttime |format-table -HideTableHeaders starttime
write-host $proc $time}
else {write-host "non existant"}
When i look at the content of the variable $time , this is what is stored
> Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
> Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Micr
> osoft.PowerShell.Commands.Internal.Format.FormatEntryData
> Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
> Microsoft.Powe rShell.Commands.Internal.Format.FormatEntryData
> Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
> Microsoft.PowerShell.Com mands.Internal.Format.FormatEntryData
> Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
> Microsoft.PowerShell.Commands.Inte rnal.Format.FormatEntryData
> Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
> Microsoft.PowerShell.Commands.Internal.Forma t.FormatEntryData
> Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
> Microsoft.PowerShell.Commands.Internal.Format.FormatEn tryData
> Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
> Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Micro
> soft.PowerShell.Commands.Internal.Format.FormatEndData
Basicaly , what i would like to end with is a script that shows every PID and Startime for a particular application. The $time var would need to store the date "2022-08-18 1:08:39 PM"
I would also create another variable called $id which would store the PID of each process.
1408 notepad Started 2022-08-18 1:08:39 PM
Or for applications with multiple processes
1409 chrome Started 2022-08-18 1:08:39 PM
14264 chrome Started 2022-08-18 1:08:40 PM
4567 chrome Started 202...
For the ones that have multiple processes , I guess I would use an foreach statement and go through every PID available in the variable ? Still new at this so if you have any advice on how to go about it would be appreciated , but in regards to what I know , a foreach statement would help me with this.