powershell - 在脚本中获取随机的“InputObject”验证错误
问题描述
执行我的脚本时,我收到一个我不太理解的错误。它告诉我存在验证错误。
我已经测试了一些不同的变化,但它一直归结为相同的错误。
ForEach ($Index in $SQLServer)
{
$ServiceStatus = Invoke-Command {Get-Service 'MSSQLSERVER'} -comp $Index
while ($FilteredService.Status -ne 'Running')
{
Invoke-Command {Start-Service $ServiceStatus} -comp $Index
Write-Host $ServiceStatus.Status
Write-Host "SQL Service starting on " $Index
function Check-Status
{
Start-Sleep -seconds 30
$ServiceStatus.Refresh()
if ($ServiceStatus.Status -eq 'Running')
{
Write-Host "SQL Service running"
}
else
{
Check-Status
}
}
}
}
错误是这样的:
Cannot validate argument on parameter 'InputObject'.The argument is null or empty. Provide an arguemnt that is not null or empty, and then try the command again.
+ CategoryInfo : InvalidData: (:) [Start-Service], ParameterBindingValidationException
+ FullyQualifiedErrorId: ParameterArgumentValidationError...
通常,一旦某些参数尚未初始化,就会发生此错误,但我无法弄清楚是哪个参数。任何帮助,将不胜感激。
编辑:
ForEach ($Index in $SQLServer)
{
$ArrayService = Invoke-Command {Get-Service -Name 'MSSQLSERVER'} -comp $Index
if ($ArrayService.Status -ne 'Running')
{
Invoke-Command {Start-Service $script:ArrayService} -comp $Index
Write-Host $ArrayService.Status
Write-Host "SQL Service starting on " $Index
function Check-Status
{
Start-Sleep -seconds 30
$ArrayService.Refresh()
if ($ArrayService.Status -eq 'Running')
{
Write-Host "SQL Service running"
}
else
{
Check-Status
}
Check-Status
}
}
}
解决方案
推荐阅读
- javascript - 如何在 JavaScript/TypeScript 中创建具有非唯一键的地图?
- python - Travis-CI 读取拉取请求的内容并更新 repo 的 README.md
- c - 如何理解这个 C 宏?
- ms-access - MS Access:将表行/查询行合并到现有表
- excel - 计算与位置相关的唯一日期
- java - 排除基于 Java 的编译器的文件扩展名?
- performance - 当我尝试在一组两个单选按钮上实现 setOnCheckedListener 的代码时,我的应用程序崩溃了
- python - Tensorflow:ValueError:应定义“密集”输入的最后一个维度。找到`无`
- swift - 如何在 Swift 4 Cocoa 应用程序的开头弹出两个窗口?
- javascript - 传单奇怪的地图大小和平铺行为