本文只适合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>