我以为我得到了所有的容器
$containers = Get-ChildItem -path $Path -recurse | ? {$_.psIscontainer -eq $true},但它似乎只返回了我的$Path. 我真的很想$containers包含$Path及其子目录。我试过这个:
$containers = Get-Item -path $Path | ? {$_.psIscontainer -eq $true}
$containers += Get-ChildItem -path $Path -recurse | ? {$_.psIscontainer -eq $true}
Run Code Online (Sandbox Code Playgroud)
但它不允许我这样做。我是否使用Get-ChildItem错误,或者如何$Path通过将 Get-Item 和 Get-ChildItem 与 -recurse 组合来让 $containers 包含和它的 $subdirectories?
我想获得stdout和stderr运行一个Java进程,并看到了似乎是一个简单的,冷静的方式来做到这一点,但它没有工作:
$command = "java -jar secretserver-jconsole.jar -s 123456 Password"
Invoke-Expression $command -OutVariable output -ErrorVariable errors
Write-Host "stdout: $output"
Write-Host "stderr: $errors"
Run Code Online (Sandbox Code Playgroud)
没有显示$output或$errors。
我现在正在使用:
$output = cmd /c $command
Run Code Online (Sandbox Code Playgroud)
这确实让我得到了一些stdout,但它并不理想,因为我想要$error消息。
我什至尝试了这种精心设计的方法,但它似乎没有运行我认为的流程,因为它几乎立即返回,而且我知道正常流程任务几秒钟。它也没有显示输出或错误:
$psi = New-object System.Diagnostics.ProcessStartInfo
$psi.CreateNoWindow = $true
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.FileName = 'java'
$psi.Arguments = @("-jar","secretserver-jconsole.jar","-
s","123456","Password")
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $psi
[void]$process.Start()
$output = $process.StandardOutput.ReadToEnd()
$process.WaitForExit()
Write-Host "stdout: $output" …Run Code Online (Sandbox Code Playgroud) 表有
User Value
john 284
john 200
john 5
sally 245
sally 180
sally 10
bill 90
bill 1000
bill 284
greg 10
greg 90
greg 2000
Run Code Online (Sandbox Code Playgroud)
例如,如果User的值为284,那么我希望结果集不包含他我不知道如何检查User的所有行以查看是否存在284值,然后在结果集中不显示该用户在那儿.结果集应该是不同的.
最终结果集应该是
User
greg
sally
Run Code Online (Sandbox Code Playgroud)