ファイルパスの変数でstart-processを使用する方法は?(Windows10 / Powershell)


1

以下のコードを考慮してください(.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.

私が間違っている可能性のあるアイデアはありますか?どうもありがとう


1
どうですか:start-process "$($env:windows)\security\$latest.name"
LotPings

1
それは文字列は、あなたが素敵なtoString()を持っていますが、それ自体は容易文字列ではない方法で、一緒にオブジェクトを壊している第二に、ある第一の例$ファイル内のオブジェクトの問題対文字列(のように見えます試してみてください。start-process "$($env:windows)\security\$($latest.name)代わりに
Ruscalを

2
ただ、気づい@LotPingsはパンチに私を打つ、しかし、あなたは囲むかっこする必要がある$latest.nameとして、$($latest.name)望ましい結果を取得します。>start-process "$($env:windows)\security\$($latest.name)"
ラスカル

@Ruscal Yepp、それを見落としていました。
LotPings
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.