[22]Window PowerShell DSC学习系列---- 如何用PowerShell脚本查看DSC服务器的执行报表(Report)

原创 2017年02月14日 13:45:37

本文只适合DSC 5.x的版本。我们知道在DSC 5.x的版本中,Pull服务器和Report是安装在一起的。那么当目标节点注册成功到Pull和Report服务器之后,且Pull服务器上的MOF和Resource文件都部署好之后,目标节点就会间隔固定的时间到Pull服务器上去取MOF配置文件。第一次取到相对于的MOF文件后,就会立马执行,并把相应的执行结果返回给Report服务器(成功的话,就是成功的输出信息,失败的话,就会包括失败的错误信息),那么这个时候,我应该如何查看执行特定客户节点返回的结果呢?有很多的方式。下面笔者就给大家介绍3中。

@通过浏览器直接访问

在浏览器中输入下面的地址,其中pullserver.example.com为服务器的地址。

http://pullserver.example.com:8080/PSDSCPullServer.svc/Nodes(AgentId='199404F3-E202-11E6-80B8-BE117D36B7A4')/Reports

那么AgentId如何知道的呢? 登陆目标节点机器,pullClient.example.com,运行下面的命令,就可以得到上面的AgentID

PS C:\DSC> $((glcm).AgentId)
199404F3-E202-11E6-80B8-BE117D36B7A4


@通过PowerShell脚本访问

执行下面的PowerShell脚本,可以获得其report的结果。
function GetReport
{
    param($AgentId = "$((glcm).AgentId)", $serviceURL = "http://pullserver.example.com:8080/PSDSCPullServer.svc")
    $requestUri = "$serviceURL/Nodes(AgentId= '$AgentId')/Reports"
    $request = Invoke-WebRequest -Uri $requestUri  -ContentType "application/json;odata=minimalmetadata;streaming=true;charset=utf-8" `
               -UseBasicParsing -Headers @{Accept = "application/json";ProtocolVersion = "2.0"} `
               -ErrorAction SilentlyContinue -ErrorVariable ev
    $request.content
    $object = ConvertFrom-Json $request.content


    return $object.value
}
GetReport

@通过Fiddler访问

打开Fiddler 4, 然后点击Composer tab,在字的Raw Tab中输入下面的内容后,点击Execute按钮。就能查看到返回结果。

GET http://pullserver.example.com:8080/PSDSCPullServer.svc/Nodes(AgentId='199404F3-E202-11E6-80B8-BE117D36B7A4')/Reports HTTP/1.1
Host: pull51w2k12nssl:8080
Connection: keep-alive
Upgrade-Insecure-Requests: 1
ProtocolVersion: 2.0
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4


如果是Basic认证,还需要加上Authorization的HTTP认证头,类似于下面

Authorization: Basic YWRtaW46dGVzdA==

其中YWRtaW46dGVzdA==是"admin:test" 做base64 编码之后生成的。

@通过直接查看Report的数据库

首先把Pull服务器的IIS暂时停止一下,然后把其默认的数据库文件拷贝到桌面

C:\Program Files\WindowsPowerShell\DscService\Devices.edb

下载一个edb的数据库的查看器软件,比如ESEDatabaseView

然后用其打开Devices.edb文件。进入StatusReport表,其Report结果如下:


@通过Advanced Rest Client 的Chrome浏览器插件

可以通过Advanced Rest Client的Chrome的浏览器插件进行访问,所以需要先安装Advanced Rest Client的Chrome的浏览器插件。调用的过程如下图所示意:






最后给大家附上部分返回结果浏览器,PowerShell和Fiddler返回的部分结果。

<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="http://pullserver.example.com:8080/PSDSCPullServer.svc/" xmlns="http://www.w3.org/2005/Atom"
	xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
	xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
	xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
	<id>http://pullserver.example.com:8080/PSDSCPullServer.svc/Nodes(AgentId='199404F3-E202-11E6-80B8-BE117D36B7A4')/Reports
	</id>
	<title type="text">Reports</title>
	<updated>2017-02-14T05:16:18Z</updated>
	<link rel="self" title="Reports" href="Reports" />
	<entry>
		<id>http://pullserver.example.com:8080/PSDSCPullServer.svc/Reports('015c5282-f265-11e6-80bc-c528ec5710e7')
		</id>
		<category term="MSFT.DSCReport"
			scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
		<link rel="edit" title="DSCReport"
			href="Reports('015c5282-f265-11e6-80bc-c528ec5710e7')" />
		<link
			rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Nodes"
			type="application/atom+xml;type=entry" title="Nodes"
			href="Reports('015c5282-f265-11e6-80bc-c528ec5710e7')/Nodes" />
		<title />
		<updated>2017-02-14T05:16:18Z</updated>
		<author>
			<name />
		</author>
		<content type="application/xml">
			<m:properties>
				<d:JobId>015c5282-f265-11e6-80bc-c528ec5710e7</d:JobId>
				<d:OperationType>LocalConfigurationManager</d:OperationType>
				<d:RefreshMode>Pull</d:RefreshMode>
				<d:Status>Failure</d:Status>
				<d:ReportFormatVersion>2.0</d:ReportFormatVersion>
				<d:ConfigurationVersion>2.0.0</d:ConfigurationVersion>
				<d:StartTime m:type="Edm.DateTime">2017-02-14T03:23:51.982
				</d:StartTime>
				<d:EndTime m:type="Edm.DateTime">2017-02-14T03:23:53.982</d:EndTime>
				<d:RebootRequested>False</d:RebootRequested>
				<d:Errors m:type="Collection(Edm.String)" />
				<d:StatusData m:type="Collection(Edm.String)">
					<d:element>{"StartDate":"2017-02-14T03:23:51.9820000+00:00","Error":"Registration
						of the Dsc Agent with the server
						http://pull51w2k12nssl:8080/PSDSCPullServer.svc failed. The
						underlying error is: Cannot register at
						http://pull51w2k12nssl:8080/PSDSCPullServer.svc. Registering over
						HTTP is not allowed. To ensure security in registration, use an
						HTTPS address for the ServerUrl in the ConfigurationRepository of
						the LocalConfigurationManager resource for this device. If you
						understand the security implications of using HTTP and want to
						allow its use on this device, set AllowUnsecureConnection property
						to true in the ConfigurationRepository of the
						LocalConfigurationManager resource for this device.
						.","IPV6Addresses":["fe80::55d7:2403:fd6a:568f%12","::2000:0:0:0","::1","::2000:0:0:0","2001:0:338c:2b9f:18e3:44:3f57:feaf","fe80::18e3:44:3f57:feaf%14"],"DurationInSeconds":"2","JobID":"{015C5282-F265-11E6-80BC-C528EC5710E7}","MACAddresses":["FA-16-3E-BC-BF-52","00-00-00-00-00-00-00-E0","00-00-00-00-00-00-00-E0"],"MetaData":"Author:
						Admin; Name: PullClientConfigNames; Version: 2.0.0;
						GenerationDate: 02/14/2017 03:23:51; GenerationHost:
						DSCC51W2008NSSL;","Status":"Failure","IPV4Addresses":["192.168.1.80","127.0.0.1"],"LCMVersion":"2.0","CurrentChecksum":"22250721B388995018BD8A76BC89CF96AA4A2B65492DCCC10712A8D22566B273","NumberOfResources":"0","Type":"LocalConfigurationManager","HostName":"DSCC51W2008NSSL","RebootRequested":"False","Mode":"Pull","Locale":"en-US"}
					</d:element>
				</d:StatusData>
				<d:AdditionalData m:type="Collection(MSFT.PropertyBag)">
					<d:element>
						<d:Key>OSVersion</d:Key>
						<d:Value>{"VersionString":"Microsoft Windows NT
							6.3.9600.0","ServicePack":"","Platform":"Win32NT"}</d:Value>
					</d:element>
					<d:element>
						<d:Key>PSVersion</d:Key>
						<d:Value>{"CLRVersion":"4.0.30319.42000","PSVersion":"5.1.14409.1005","BuildVersion":"10.0.14409.1005"}
						</d:Value>
					</d:element>
				</d:AdditionalData>
			</m:properties>
		</content>
	</entry>
	<entry>
		<id>http://pullserver.example.com:8080/PSDSCPullServer.svc/Reports('a7c972f0-f26e-11e6-80bc-c528ec5710e7')
		</id>
		<category term="MSFT.DSCReport"
			scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
		<link rel="edit" title="DSCReport"
			href="Reports('a7c972f0-f26e-11e6-80bc-c528ec5710e7')" />
		<link
			rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Nodes"
			type="application/atom+xml;type=entry" title="Nodes"
			href="Reports('a7c972f0-f26e-11e6-80bc-c528ec5710e7')/Nodes" />
		<title />
		<updated>2017-02-14T05:16:18Z</updated>
		<author>
			<name />
		</author>
		<content type="application/xml">
			<m:properties>
				<d:JobId>a7c972f0-f26e-11e6-80bc-c528ec5710e7</d:JobId>
				<d:OperationType>Consistency</d:OperationType>
				<d:RefreshMode>Pull</d:RefreshMode>
				<d:Status>Success</d:Status>
				<d:ReportFormatVersion>2.0</d:ReportFormatVersion>
				<d:ConfigurationVersion>2.0.0</d:ConfigurationVersion>
				<d:StartTime m:type="Edm.DateTime">2017-02-14T04:32:56.701
				</d:StartTime>
				<d:EndTime m:type="Edm.DateTime">2017-02-14T04:33:04.701</d:EndTime>
				<d:RebootRequested>False</d:RebootRequested>
				<d:Errors m:type="Collection(Edm.String)" />
				<d:StatusData m:type="Collection(Edm.String)">
					<d:element>{"StartDate":"2017-02-14T04:32:56.7010000+00:00","IPV6Addresses":["fe80::55d7:2403:fd6a:568f%12","::2000:0:0:0","::1","::2000:0:0:0","2001:0:338c:2b9f:185f:b3d:3f57:feaf","fe80::185f:b3d:3f57:feaf%14"],"DurationInSeconds":"8","JobID":"{A7C972F0-F26E-11E6-80BC-C528EC5710E7}","CurrentChecksum":"22250721B388995018BD8A76BC89CF96AA4A2B65492DCCC10712A8D22566B273","MetaData":"Author:
						Admin; Name: testzip; Version: 2.0.0; GenerationDate: 02/14/2017
						03:20:09; GenerationHost:
						PULL51W2K12NSSL;","RebootRequested":"False","Status":"Success","IPV4Addresses":["192.168.1.80","127.0.0.1"],"LCMVersion":"2.0","NumberOfResources":"1","Type":"Consistency","HostName":"DSCC51W2008NSSL","ResourcesInDesiredState":[{"SourceInfo":"::5::7::Archive","ModuleName":"PSDesiredStateConfiguration","DurationInSeconds":"0.391","InstanceName":"ArchiveExample","StartDate":"2017-02-14T04:33:04.9510000+00:00","ResourceName":"Archive","ModuleVersion":"1.1","RebootRequested":"False","ResourceId":"[Archive]ArchiveExample","ConfigurationName":"testzip","InDesiredState":"True"}],"MACAddresses":["FA-16-3E-BC-BF-52","00-00-00-00-00-00-00-E0","00-00-00-00-00-00-00-E0"],"MetaConfiguration":{"AgentId":"199404F3-E202-11E6-80B8-BE117D36B7A4","ConfigurationDownloadManagers":[{"SourceInfo":"::15::9::ConfigurationRepositoryWeb","AllowUnsecureConnection":"True","ServerURL":"http://pull51w2k12nssl:8080/PSDSCPullServer.svc","RegistrationKey":"","ResourceId":"[ConfigurationRepositoryWeb]pull51w2k12nssl","ConfigurationNames":["unzipFile"]}],"ActionAfterReboot":"ContinueConfiguration","LCMCompatibleVersions":["1.0","2.0"],"LCMState":"Idle","ResourceModuleManagers":[],"ReportManagers":[{"AllowUnsecureConnection":"True","RegistrationKey":"","ServerURL":"http://pull51w2k12nssl:8080/PSDSCPullServer.svc","ResourceId":"[ReportServerWeb]pull51w2k12nssl","SourceInfo":"::24::9::ReportServerWeb"}],"StatusRetentionTimeInDays":"10","LCMVersion":"2.0","MaximumDownloadSizeMB":"500","ConfigurationMode":"ApplyAndAutoCorrect","RefreshFrequencyMins":"30","RebootNodeIfNeeded":"True","SignatureValidationPolicy":"NONE","RefreshMode":"Pull","DebugMode":["NONE"],"LCMStateDetail":"","AllowModuleOverwrite":"False","ConfigurationModeFrequencyMins":"15","SignatureValidations":[]},"Locale":"en-US","Mode":"Pull"}
					</d:element>
				</d:StatusData>
				<d:AdditionalData m:type="Collection(MSFT.PropertyBag)">
					<d:element>
						<d:Key>OSVersion</d:Key>
						<d:Value>{"VersionString":"Microsoft Windows NT
							6.3.9600.0","ServicePack":"","Platform":"Win32NT"}</d:Value>
					</d:element>
					<d:element>
						<d:Key>PSVersion</d:Key>
						<d:Value>{"CLRVersion":"4.0.30319.42000","PSVersion":"5.1.14409.1005","BuildVersion":"10.0.14409.1005"}
						</d:Value>
					</d:element>
				</d:AdditionalData>
			</m:properties>
		</content>
	</entry>
</feed>

版权声明:本文为博主原创文章,未经博主允许不得转载。

[27] Window PowerShell DSC 学习系列----DSC 5.x 查询节点注册和执行报告(Report)查询

我们知道,一旦我们把DSCD额Pull服务器安装成功,且目标节点也注册成功后,我们就可以调用DSC服务的oData的查询。去查询一些信息。请注意,浏览器可能不支持oData的Http的get操作。因此...

[10] Window PowerShell DSC 学习系列----目标节点和Pull 服务器底层通信原理剖析

在本节中,笔者将会用wireshark抓包,并分析目标节点如何和Pull 服务器通信的?注意笔者本机装的Window Management Framework 5.1,如果是其他的版本,可能请求的UR...

[26]Window PowerShell DSC学习系列----如何更换Pull服务器数据库为SQL Server数据库

上节我们提到了如何把PowerShell DSC的数据库换成Access;DSC Pull服务器当前的版本对MS SQL Server是不支持的,该怎么办?另外如果我们需要对Pull服务器建立负载均衡...

[24]Window PowerShell DSC学习系列---- 如何保护MOF文件里面存储的密码?

在上节笔者分享了[23]Window PowerShell DSC学习系列---- MOF文件能存储用户的密码吗?MOF文件里面能直接存储明文密码,这样是非常不安全的。那么有什么方式能够把MOF里面存...

[23]Window PowerShell DSC学习系列---- MOF文件能存储用户的密码吗?

我们知道,DSC的资源中,有很多的资源是需要访问文件共享目录,进入本地的用户的目录,或者为一个特定的用户安装一个MSI的安装包,修改注册表;这个时候,如果直接执行调用DSC的资源,则可能会弹出“Acc...

[7] Window PowerShell DSC 学习系列----如何被管理的设置节点注册到Pull Server?

在上一节,[6] Window PowerShell DSC 学习系列----如何安装最新的PowerShell DSC 5.1 Pull Server?笔者聊到了如何安装Pull Server。那么...

[20]Window PowerShell DSC学习系列---- start-dscconfiguration 中遇到 Access Denied的解决方案

当我们执行start-DscConfiguration -computername psdsc-window201 -Path c:\DSC\TestFile -Wait -Verbose -forc...

[9] Window PowerShell DSC 学习系列----错误诊断和分析

PowerShell DSC就像一个汽车,内部复杂,司机作为一个普通的用户在使用它,因为知道一些汽车的基本常识,所以当汽车发生一些简单的故障时,可以通过汽车自身带的仪表仪器诊断问题出在哪方面,也可以借...

[17]Windows PowerShell DSC学习系列---使用WMI Tester调用msft-dsclocalconfigurationmanager类的方法

在这边文章中,其列出了DSC中的本地配置管理引擎中的msft-dsclocalconfigurationmanager类,其列出了这个类中的很多方法。比如GetConfigurationStatus,...

[2] Window PowerShell DSC 学习系列----DSC的资源(Resource)以及配置和格式(Configuration && Sytax )

这个章节主要来讲述DSC的资源(Resource)以及配置和格式(Configuration && Sytax )。...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:[22]Window PowerShell DSC学习系列---- 如何用PowerShell脚本查看DSC服务器的执行报表(Report)
举报原因:
原因补充:

(最多只允许输入30个字)