我想从字符串中删除localhost,但以下命令不起作用。有没有什么好主意?
选项1:
[string[]]$Servers = '"localhost","tbhserver"'
$Servers = $servers | Where-Object {$_ -ne "localhost"}选项2:
[string[]]$Servers = '"localhost","tbhserver"'
$Servers
[System.Collections.ArrayList]$servers = $servers
$servers.Remove("localhost")发布于 2012-04-08 22:58:37
在我看来,您只是将一个字符串'"localhost",“tbhserver”“赋给了$Servers,而不是两个字符串的列表。
这行得通吗?
$Servers = @("localhost", "tbhserver")
$Servers = $Servers | Where-Object {$_ -ne "localhost"}我现在不在Windows机器上,所以我不能测试它。
发布于 2012-04-09 00:03:07
您还可以使用-ne参数:
$servers = 'localhost', 'tbhserver'
$servers = $servers -ne 'localhost'https://stackoverflow.com/questions/10063718
复制相似问题