我有以下 power-shell 脚本,我想在其中获取我们服务器的 ServiceTag:-
((Get-VMHost | Get-View).Hardware.SystemInfo.OtherIdentifyingInfo | ?{$_.IdentifierType.Key -like "ServiceTag"}).IdentifierValue
但我注意到,对于某些服务器,我会得到 2 个代表服务标签的值,这正常吗?如果是这样,那么我可以使用哪个来识别服务器?
编辑 当我运行这个脚本时:-
((Get-VMHost | Get-View).Hardware.SystemInfo.OtherIdentifyingInfo | ?{$_.IdentifierType.Key -like "ServiceTag"}).IdentifierValue
foreach ($vmhost in Get-VMHost) {
$ServiceTag = $vmhost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo; $ServiceTag | Get-Member
if ([string]::IsNullOrEmpty($ServiceTag)) { $ServiceTag = 'N/A' }
Write-Host "$($vmhost.Name) - $ServiceTag"
}
我明白了:-
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
DynamicProperty Property VMware.Vim.DynamicProperty[] DynamicProperty {get;set;}
DynamicType Property string DynamicType {get;set;}
IdentifierType Property VMware.Vim.ElementDescription IdentifierType {get;set;}
IdentifierValue Property string IdentifierValue {get;set;}
最佳答案
这实际上是一条评论,但因为它需要在多行中格式化,所以我将其添加为一个答案
如果你这样做会发生什么
foreach ($vmhost in Get-VMHost) {
$ServiceTag = $vmhost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo |
Where-Object { $_.IdentifierType.Key -eq "ServiceTag"}
if ([string]::IsNullOrEmpty($ServiceTag)) { $ServiceTag = 'N/A' }
Write-Host "$($vmhost.Name) - $ServiceTag"
}
看来上面没有返回带有服务标签的字符串,而是一个对象。该对象有一个 IdentifierValue 属性,它包含带有实际服务标签的字符串。所以我们需要更深入一步:
foreach ($vmhost in Get-VMHost) {
$ServiceTag = $vmhost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo |
Where-Object { $_.IdentifierType.Key -eq "ServiceTag"}
if (($ServiceTag) -and $ServiceTag.IdentifierValue) {
$ServiceTag = $ServiceTag.IdentifierValue
}
Write-Host "$($vmhost.Name) - $ServiceTag"
}
编辑
从物理服务器获取序列号时,您似乎必须处理硬件供应商公开这些属性的方式。不同的供应商以不同的方式对待它们。
您已经尝试过的各种代码都会为 IdentifierValue 返回两个值。
发生这种情况是因为硬件供应商(如 Cisco)提供了每个处理器的序列号。
发现here .
向下滚动到 ESXi Physical Servers 章节
关于windows - PowerShell 脚本 "Get-VMHost Hardware.SystemInfo.OtherIdentifyingInfo"将为服务标签返回 2 个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51934516/
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我有一个在Linux服务器上运行的ruby脚本。它不使用rails或任何东西。它基本上是一个命令行ruby脚本,可以像这样传递参数:./ruby_script.rbarg1arg2如何将参数抽象到配置文件(例如yaml文件或其他文件)中?您能否举例说明如何做到这一点?提前谢谢你。 最佳答案 首先,您可以运行一个写入YAML配置文件的独立脚本:require"yaml"File.write("path_to_yaml_file",[arg1,arg2].to_yaml)然后,在您的应用中阅读它:require"yaml"arg
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file