以下のコードを考慮してください(.ps1スクリプト内)
$latest = Get-ChildItem -Path $env:windows\security -Filter "my-app-here*.*" | Sort-Object -Descending | Select-Object -First 1
$file=$env:windows+"\security\"+$latest.name
start-process $file
これは正常に動作します。
コードを次のように単純化しようとすると:
$latest = Get-ChildItem -Path $env:windows\security -Filter "my-app-here*.*" | Sort-Object -Descending | Select-Object -First 1
start-process $env:windows+"\security\"+$latest.name
エラーメッセージが表示されます。
start-process : This command cannot be run due to the error: The system cannot find the file specified.
私が間違っている可能性のあるアイデアはありますか?どうもありがとう
それは文字列は、あなたが素敵なtoString()を持っていますが、それ自体は容易文字列ではない方法で、一緒にオブジェクトを壊している第二に、ある第一の例$ファイル内のオブジェクトの問題対文字列(のように見えます試してみてください。
—
Ruscalを
start-process "$($env:windows)\security\$($latest.name)
代わりに
ただ、気づい@LotPingsはパンチに私を打つ、しかし、あなたは囲むかっこする必要がある
—
ラスカル
$latest.name
として、$($latest.name)
望ましい結果を取得します。>start-process "$($env:windows)\security\$($latest.name)"
@Ruscal Yepp、それを見落としていました。
—
LotPings
start-process "$($env:windows)\security\$latest.name"