Можно ли отследить, откуда выводится (на консоль) сценарий Powershell?У меня есть скрипт, который выводит информацию для меня, но я не уверен, какая строка выводит.Можно ли, например, использовать Set-PSBreakpoint и сказать ему, чтобы он прерывался при возврате информации на консоль?
Приветствия
Я получаю сотни "Ложь"возвращаются по своим линиям.Вот часть кода, из которой поступает вывод:
$ar = Function-which_returns_array_of_objects
$gr = Function-which_returns_array_of_objects
Write-Host "To begin with..."
Write-Host "$($ar.count) assets"
Write-Host "$($gr.count) goods"
foreach($asset in $ar){
if(!(Test-NoNA -string $asset.Serial)){continue}
#See if the particular serial number exists in Goods Received
$found = @()
$gr | Where {$_.SerialNumber -eq $asset.serial} | %{
$found += $_
# and then mark the entry as one that has to be deleted from GR
$_.Delete = "YES"
}
if($found.count -eq 1){
#Serial Number has been found once in GR
#We want to check its PN...
if(Test-NoNA -string $found.PartNumber -and $found.PartNumber -ne $asset.Model){
#add it to the asset if its good and not the same as the model number...
$asset.PartNumber -eq $found.PartNumber
}
}elseif(!$found -or $found.count -eq 0){
#No entries found in GR
#Shouldn't be the case but doesn't actually do any damage as we'd be deleting the GR entry anyway
}elseif($found.count -gt 1){
#More than one match for the SN - probably means a SN like "N/A" has got through the earlier checks
Write-Warning "More than one match for SN: '$($asset.serial)'"
}else{
#Default catcher
Write-Warning "Unknown Error for SN: '$($asset.serial)'"
}
}
Также здесь есть Test-NoNA:
function Test-NoNA($string){
#check that the given string is not blank, N/A, ?, etc. Returns true if string is good
if($string -and $string -ne "" -and $string -ne "N/A" -and $string -ne "NA" -and $string -ne '?' -and $string -isnot [System.DBNull]){return $true}
}