簡體   English   中英

PowerShell/Pester function 調用丟失的日志和交互

[英]PowerShell/Pester function invoke missing logs and interactivity

這是我的設置(簡化),我在其中創建一個 function 並將其傳遞給Run-Test ,然后Run-Test調用 function。但是發生的事情是我只看到警告消息。 我想知道有沒有辦法以交互方式准確地查看它在每一步和每行中的作用?

function Run-Test
{
    param(
        [Parameter(Mandatory = $true)]$test,
        [Parameter(Mandatory = $true)]$name,
        [Parameter(Mandatory = $true)]
        [Alias('resourceGroupName')]
        [String[]]$resourceGroupNames
    )

    Describe $name {
        Context "BeforeEach/AfterAll" {
            BeforeAll {
                Write-Output "Cleaning up before running test: $name"
                foreach ($rgName in $resourceGroupNames)
                {
                    Unlock-ResourceGroup -Name $rgName
                }
            }
        
            AfterAll {
                Write-Output "Cleaning up after running test: $name"
                foreach ($rgName in $resourceGroupNames)
                {
                    Unlock-ResourceGroup -Name $rgName
                }
            }
            
            It "Should succeed failover and failback" $test
        }
    }
}
    

Run-Test `
    -Name "Testing ..." `
    -ResourceGroupName $primaryResourceGroupName, $recoveryResourceGroupName -Test {

 # Create primary and recovery resource groups
 New-AzResourceGroup -name $recoveryResourceGroupName -location $location -force
 New-AzResourceGroup -name $primaryResourceGroupName -Location $location -Force

 $primaryResourceGroupId = (Get-AzResourceGroup -Name $primaryResourceGroupName).ResourceId
 $recoveryResourceGroupId = (Get-AzResourceGroup -Name $recoveryResourceGroupName).ResourceId

 # print these
 $primaryResourceGroupId
 $recoveryResourceGroupId
} 

使用 PowerShell ISE,您可以調試腳本以准確查看每一行發生的情況。

在 ISE 中打開您的腳本。 當您在 .ps1 文件的上下文菜單中選擇“編輯”時,這是默認設置。 或者打開 ISE,然后從那里打開腳本。
現在在要開始調試的位置設置一個斷點:將 cursor 放在您選擇的行中,然后按 F9。
現在運行腳本。 它應該停在那條線上。 您現在可以逐行單步執行腳本並檢查發生了什么。

來源: https://devblogs.microsoft.com/scripting/use-the-powershell-debugger/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM