如何在没有密码提示的情况下 运行 Test-DbaNetworkLatency?

How can I run Test-DbaNetworkLatency without password prompt?

我 运行宁 Test-DbaNetworkLatency -SqlCredential sapowershell 测量 sql 服务器网络延迟。每次我 运行 命令时它都会提示输入密码。我计划在我的服务器上安排一个 cronjob 定期执行 运行 这个命令,所以我正在寻找一种方法来避免每次都输入密码。谁能告诉我如何在 powershell 中实现它?

您需要为该函数创建一个凭据对象。 函数信息显示 Windows and SQL Authentication supported. Accepts credential objects (Get-Credential)

$password = ConvertTo-SecureString "Password" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ("sa", $password)
Test-DbaNetworkLatency -SqlCredential $creds