簡體   English   中英

通過 CMD 的 PS 腳本

[英]PS script via CMD

我正在嘗試通過 CMD 運行 PS 表達式,但出現錯誤

powershell -command "Get-ChildItem <FOLDERPATH> -Recurse -file | % { "{0}  {1}" -f $_.FullName, [System.Diagnostics.FileVersionInfo]::GetVersionInfo($_.FullName).FileVersion }

我已經確認使用單引號和雙引號可以像 Anthony Stringer 建議的那樣工作

powershell -command "Get-ChildItem <FOLDERPATH> -Recurse -file | % { '{0}  {1}' -f $_.FullName, [System.Diagnostics.FileVersionInfo]::GetVersionInfo($_.FullName).FileVersion }

問題是 '%' 字符和引號內的引號。 請改用 ForEach-Object。 不應在腳本中使用別名。 在格式化字符串上使用撇號而不是引號。

@ECHO OFF
SET "FOLDERPATH=C:/src"
powershell -NoLogo -NoProfile -Command ^
    "Get-ChildItem '%FOLDERPATH%' -Recurse -File |" ^
        "ForEach-Object { '{0}  {1}' -f $_.FullName, [Diagnostics.FileVersionInfo]::GetVersionInfo($_.FullName).FileVersion }"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM