string 为什么我不能将 ToUpper() 应用于 OwnerNode?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16963511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 01:57:42  来源:igfitidea点击:

Why can't I apply ToUpper() to an OwnerNode?

stringpowershellmethodsinvocation

提问by tkrn

This works:

这有效:

Output "Cluster Group: ""$($Group.Name)"", Current Owner: $($Group.OwnerNode), Current State: $($Group.State)"

This does not work:

这不起作用:

Output "Cluster Group: ""$($Group.Name)"", Current Owner: $($Group.OwnerNode.ToUpper()), Current State: $($Group.State)"

With an error of this:

有这样的错误:

Method invocation failed because [Microsoft.FailoverClusters.PowerShell.ClusterNode] doesn't contain a method named 'ToUpper'.

Any ideas on how to get this to string from the output of the Get-ClusterGroup string to upper case?

关于如何将其从 Get-ClusterGroup 字符串的输出转换为大写的任何想法?

回答by Shay Levy

ToUpper() is a string method and OwnerNode is probably not a string. Call the ToString() method before calling ToUpper().

ToUpper() 是一个字符串方法,而 OwnerNode 可能不是一个字符串。在调用 ToUpper() 之前调用 ToString() 方法。

$($Group.OwnerNode.ToString().ToUpper())

回答by Ansgar Wiechers

As Shay Levyalready explained, OwnerNodeis not a string and has thus not a method ToUpper(). You can call ToUpper()on its Nameproperty, though:

正如Shay Levy已经解释过的,OwnerNode不是字符串,因此也不是方法ToUpper()。不过,您可以调用ToUpper()它的Name属性:

$($Group.OwnerNode.Name.ToUpper())