Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
windows powershell脚本中的服务解释问题_Windows_Powershell - Fatal编程技术网

windows powershell脚本中的服务解释问题

windows powershell脚本中的服务解释问题,windows,powershell,Windows,Powershell,我在windows powershell中创建脚本时遇到问题。 到目前为止,我能够找到并列出包含给定字符串的服务,但是我在为每个服务分配RequiredService时遇到了一个问题。 这是我的密码 $characters = Read-Host "Enter a character string to appear in the service" $name = get-service -name *$characters* For($i=0; $i -lt $name.C

我在windows powershell中创建脚本时遇到问题。 到目前为止,我能够找到并列出包含给定字符串的服务,但是我在为每个服务分配RequiredService时遇到了一个问题。 这是我的密码

$characters = Read-Host "Enter a character string to appear in the service"
$name = get-service -name *$characters*
For($i=0; $i -lt $name.Count; $i++)
{
    Write-Host $name[$i]
    $Required = get-service -RequiredServices $name[$i]
        For($j=0; $j -lt $Required.Count; $j++)
        {
            Write-Host "          "$Required[$j]
        }
}
exit 0
这是一个问题

get-service : Cannot find any service with service name 'System.ServiceProcess.ServiceController'.
我不知道为什么每个服务,尽管显示得很好,却被进一步称为“System.ServiceProcess.ServiceController”

编辑: 我换了6号线

    $Required = get-service -RequiredServices *($name[$i])
,但脚本仍然不起作用

Get-Service : A positional parameter cannot be found that accepts argument 'XboxNetApiSvc'.

Powershell将在某些情况下为我们自动格式化对象,例如写入主机。Write Host将向您显示服务名称,因为这是服务控制器对象的默认tostring()。在命令中尝试使用名称时,只需自己指定名称即可

$characters = Read-Host "Enter a character string to appear in the service"
$name = get-service -name *$characters*
For($i=0; $i -lt $name.Count; $i++)
{
    Write-Host $name[$i]
    $Required = get-service -RequiredServices $name[$i].name
        For($j=0; $j -lt $Required.Count; $j++)
        {
            Write-Host "          "$Required[$j].name
        }
}
exit 0