I'm figuring out how to loop trough a set of files and execute a program against these files, that outputs a log and tar file as it scans a hyper-v virtual hard disk.
What I already figured out is the following: gathering all VHDX on a volume. Putting them in a variable.
However I'm stuck at processing the foreach, and having a flexible output of the tar file and log name.
Example:
Get-ChildItem -Path $VDHXPath -Filter $Extension -Recurse -ErrorAction SilentlyContinue -Force | % { $_.FullName }
Where $VHDXPath represents a customizable variable that represents the driveletter. This way I get an variable filled with one or multiple VHDX.
Than I need to execute the program against the queried/inventoried VHDX. The plane single file /straight command line is as following:
win.exe guid -o "tarfile.tar" -l "logfile.log" -p default --history "pathtovhdxfile.vhdx"
So I already tried many variants of how to do the foreach and call a command to talk against the VHDX. Example:
Foreach ($file in $files){
Start-Process -NoNewWindow -FilePath ".\win.exe" -ArgumentList "guid -o tarfile.tar -l logfile.tar -p default --history vhdxfile.vhdx"
}
Where the output of the tar file and log file, must match the name of the VHDX being processed.
I also tried:
Foreach ($file in $files){
& ".\win.exe" "guid -o tarfile.tar -l logfile.tar -p default --history vhdxfile.vhdx"
}
Unfortunately to no result. I either get the mention that the program isn't a valid powershell cmd-let or executable program. Or the program itself reacts that the tarfile, logfile and vhdxfiles are invalid, as the command line takes all the VHDX' at once.
The goal is to get a tar and logfile with the name of each VHDX it processes.
Any guidance would be highly appreciated
edit:
I'm getting a little bit furter:
$VDHXPath = "C:\Users\%USERNAME%"
$Extension = "*.VHDX"
Foreach ($file in Get-ChildItem -Path $VDHXPath -Filter $Extension -Recurse -ErrorAction SilentlyContinue -Force | % { $_.FullName }) {
& .\win.exe guid -o '.\$file.name'.tar -l '.\$file.name'.log -p default --history $file
}
So now the program walks through the files, but I'm only struggling with the per VHDX logfile name and tar file name.
Get-ChildItem?