mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add CommandLine property to Process (#12288)
This commit is contained in:
@@ -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" {
|
||||
|
||||
Reference in New Issue
Block a user