Skip to content

Commit

Permalink
Add CommandLine property to Process (PowerShell#12288)
Browse files Browse the repository at this point in the history
  • Loading branch information
iSazonov committed May 29, 2020
1 parent 2fe3499 commit c7455fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs
Expand Up @@ -1139,6 +1139,24 @@ private void Process_Types_Ps1Xml(string filePath, ConcurrentBag<string> 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,
Expand Down
Expand Up @@ -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" {
Expand Down

0 comments on commit c7455fd

Please sign in to comment.