Я пытаюсь перечислить все файлы msi, найденные в данном директоре, в файл, а затем извлечь эти файлы msi. Я пытаюсь использовать $ _ в foreach-object для прохождения пути, но, похоже, интерпретирует его как литерал вместо того, чтобы передавать путь. Я думал, что $ _ передаст объект, который в этом случае будет файловым путем, но он, похоже, не работает таким образом. Каков наилучший способ передать найденные пути к файлу функции 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