【发布时间】:2022-07-28 02:43:00
【问题描述】:
我创建一个 PowerShell 脚本只是为了备份我的 WSL 发行版,但是当我尝试使用变量运行命令时它不起作用,它会显示使用文本,就好像我提供了不正确的参数一样。
$DistrosArray1 = (wsl -l --quiet) | where {$_ -ne ""}
$DistrosArray2 = 'Arch', 'Ubuntu-22.04', 'docker-desktop-data', 'docker-desktop'
$CheckArrayDifference = Compare-Object -ReferenceObject $DistrosArray1 -DifferenceObject $DistrosArray2 -PassThru
echo $CheckArrayDifference
# Does not return anything (there is no difference)
foreach ($Distro in $DistrosArray1) {
wsl --export $Distro "$Distro.tar"
# This method is not working
}
foreach ($Distro in $DistrosArray2) {
wsl --export $Distro "$Distro.tar"
# This method is working
}
【问题讨论】:
标签: powershell windows-subsystem-for-linux