Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.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
Powershell将心跳更新到cloudwatch_Powershell_Amazon Cloudwatch - Fatal编程技术网

Powershell将心跳更新到cloudwatch

Powershell将心跳更新到cloudwatch,powershell,amazon-cloudwatch,Powershell,Amazon Cloudwatch,我试图创建一个函数来将服务器的心跳更新到cloudwatch。但是从下面的函数来看,这个函数并没有中断。。我肯定我犯了一些错误。。但我对powershell很陌生,请你帮我纠正一下 function Get-spooler{ $INSTANCE_ID=$(Invoke-WebRequest -Uri http://169.254.169.254/latest/meta-data/instance-id) $service=Get-Service -Name Spooler write-host

我试图创建一个函数来将服务器的心跳更新到cloudwatch。但是从下面的函数来看,这个函数并没有中断。。我肯定我犯了一些错误。。但我对powershell很陌生,请你帮我纠正一下

function Get-spooler{
$INSTANCE_ID=$(Invoke-WebRequest -Uri http://169.254.169.254/latest/meta-data/instance-id)
$service=Get-Service -Name Spooler 
write-host $INSTANCE_ID
write-host $service
write-host $service.Status
while($service.Status -eq 'Running')
{
aws --region ap-southeast-1 cloudwatch put-metric-data --metric-name Test13 --value 1 --namespace ssm  --dimensions InstanceId=$INSTANCE_ID
if ($service.Status -eq 'Stopped')
{
aws --region ap-southeast-1 cloudwatch put-metric-data --metric-name Test13 --value 0 --namespace ssm  --dimensions InstanceId=$INSTANCE_ID
}}}

$service在分配静态对象时存储该对象。因此,如果服务在运行时
$service=Get service-Name假脱机程序
$service.status将始终等于“running”


尝试:
while((获取服务-名称假脱机程序)。状态-eq'Running')

我尝试了下面的工作。。谢谢你检查<代码>代码函数Get spooler{$service=Get service-Name spooler write host$INSTANCE_ID write host$service write host$service.Status if($service.Status-eq'Running'){aws--region ap-southerast-1 cloudwatch put metric data--metric Name spooler_service--value 1--namespace services--dimensions InstanceId=i-09c6f94b869466e03}else{aws--地区ap-southeast-1 cloudwatch put度量数据--度量名称后台处理程序服务--值0--命名空间服务--维度InstanceId=i-09c6f94b869466e03}