From cfa1ffefd5a2782ed11d5f751fa0ff09d0cc9f1c Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 9 Apr 2020 22:25:18 +0500 Subject: [PATCH 1/2] Add CommandLine property to Process --- .../engine/TypeTable_Types_Ps1Xml.cs | 18 ++++++++++++++++++ .../Get-Process.Tests.ps1 | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs b/src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs index 6dbf181051a..7070425842e 100644 --- a/src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs +++ b/src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs @@ -1138,6 +1138,24 @@ private void Process_Types_Ps1Xml(string filePath, ConcurrentBag errors) typeMembers, isOverride: false); + newMembers.Add(@"CommandLine"); + AddMember( + errors, + typeName, + new PSScriptProperty( + @"CommandLine", + GetScriptBlock(@" + if ($IsWindows) { + (Get-CimInstance Win32_Process -Filter ""ProcessId = $($this.Id)"").CommandLine + } elseif ($IsLinux) { + Get-Content -LiteralPath ""/proc/$($this.Id)/cmdline"" + } + "), + setterScript: null, + shouldCloneOnAccess: true), + typeMembers, + isOverride: false); + newMembers.Add(@"Parent"); AddMember( errors, diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 index 2fa7ef45387..675b085c4d6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 @@ -89,6 +89,12 @@ Describe "Get-Process" -Tags "CI" { It "Should fail to run Get-Process with -FileVersionInfo without admin" -Skip:(!$IsWindows) { { Get-Process -FileVersionInfo -ErrorAction Stop } | Should -Throw -ErrorId "CouldNotEnumerateFileVer,Microsoft.PowerShell.Commands.GetProcessCommand" } + + It "Should return CommandLine property" -Skip:($IsMacOS) { + $command = "(Get-Process -Id `$pid).CommandLine" + $result = & "$PSHOME/pwsh" -NoProfile -NonInteractive -Command $command + $result | Should -BeLike "*`"$command`"" + } } Describe "Get-Process Formatting" -Tags "Feature" { From 14c92853668629abd83712470c8923b50373f7aa Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 9 Apr 2020 22:50:53 +0500 Subject: [PATCH 2/2] Fix test --- .../Microsoft.PowerShell.Management/Get-Process.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 index 675b085c4d6..a4481454890 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 @@ -93,7 +93,7 @@ Describe "Get-Process" -Tags "CI" { It "Should return CommandLine property" -Skip:($IsMacOS) { $command = "(Get-Process -Id `$pid).CommandLine" $result = & "$PSHOME/pwsh" -NoProfile -NonInteractive -Command $command - $result | Should -BeLike "*`"$command`"" + $result | Should -BeLike "*$command*" } }