在powershell中运行脚本块中的以下代码并运行它的问题
foreach($list in $an){
Write-Host "on loop :" $loop
Write-Host "Checking on VM : "$list.vm
$checkdata = (([datetime]$currentdate) - ([datetime]$list.Created.ToString().split(" ")[0])).Days
Write-Host "Check data " $checkdata
IF($checkdata -gt 2){
Write-Host "on Dupe : " $dupe
#$datecreated = $sizeinGGB = $diff = $null | Out-Null
$datecreated = ($list.Created.ToString().split(" ")[0])
Write-Host $datecreated
$sizeinGGB = [INT]$list.SizeGB
Write-Host $sizeinGGB
$diff = ((([datetime]$currentdate) - ([datetime]$list.Created)).Days)
Write-Host $diff
$repo = [ordered] @{
vm = $list.vm
SNapshotname = $list.Name
DateCreated = $datecreated
Snapshotold = $diff
SizeinGB = $sizeinGGB
}
New-Object PSobject -Property $repo
$dupe ++
}ELSE{
Write-Host $list.vm " : Looks Good"
}
$loop ++
}
如果我删除$ repo赋值语句,我的脚本运行良好。如果我把它放在脚本上,那么脚本就会停止在$ repo block上执行