Add CommandLine property to Process (#12288)

This commit is contained in:
Ilya
2020-05-29 11:33:49 -07:00
committed by GitHub
parent 2fe34993c3
commit c7455fd4d8
2 changed files with 24 additions and 0 deletions
@@ -1139,6 +1139,24 @@ namespace System.Management.Automation.Runspaces
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,
@@ -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" {