0
特定のdirで見つかったすべてのmsiファイルをファイルにリストし、それらのmsiファイルを抽出しようとしています。 foreachオブジェクトで$ _を使用してパスを渡そうとしていますが、パスを渡す代わりにリテラルとして解釈しているようです。私は$ _がオブジェクトを渡すと思っていましたが、この場合はファイルパスになりますが、そのように機能しているようには見えません。見つかったファイルパスをExport-MsiContents関数に渡す適切な方法は何ですか?Powershell適切な方法でオブジェクトを関数に渡す
Function Export-MsiContents
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, Position=0)]
[ValidateNotNullOrEmpty()]
[ValidateScript({Test-Path $_})]
[ValidateScript({$_.EndsWith(".msi")})]
[String] $MsiPath,
[Parameter(Mandatory=$false, Position=1)]
[String] $TargetDirectory
)
if(-not($TargetDirectory))
{
$currentDir = [System.IO.Path]::GetDirectoryName($MsiPath)
Write-Warning "A target directory is not specified. The contents of the MSI will be extracted to the location, $currentDir\Temp"
$TargetDirectory = Join-Path $currentDir "Temp"
}
$MsiPath = Resolve-Path $MsiPath
Write-Verbose "Extracting the contents of $MsiPath to $TargetDirectory"
Start-Process "MSIEXEC" -ArgumentList "/a $MsiPath /qn TARGETDIR=$TargetDirectory" -Wait -NoNewWindow
}
$Dir = get-childitem d:\temp\test -recurse
$List = $Dir | where {$_.extension -eq ".msi"}
$List | format-table fullname | out-file d:\temp\test\msilist.txt
$List | ForEach-Object {Export-MsiContents -MsiPath $_}
はい!いいキャッチ!ありがとう! – nousername