Out-String + TrimStart 命令

问题描述 投票:0回答:1

命令

$serverInfoSheet.Cells.Item($row,$column)= Get-VM | Where-Object { $_.Name -match $server.Name} | fl Name | Out-String
得到以下结果“名称:bra-rj-cons-dc2.domain.org”。

我尝试在管道末尾使用 {$_.TrimStart('Name : ')} 但找不到任何与 Pipeline 和 Trim 配合使用的东西。

我只需在写入 CSV 文件之前删除“名称:”即可。

powershell vmware
1个回答
0
投票

我必须想出另一种方法来让它发挥作用。这是任何需要的人的代码。

观察:。我尝试将代码放入代码示例中,但无法以正确的方式填写。对此感到抱歉。

获取虚拟机 |选择对象-展开属性“名称”> C: emp\sccm.txt

$file = 获取内容-路径 C: emp\sccm.txt

$servers = Get-CMCollection -名称“SRV_WU_SCCM_Mgmt”|获取 CMCollectionMember |选择对象名称 $deploymentDate = Get-CMDeployment -CollectionName“SRV_WU_SCCM_Mgmt”|选择对象强制执行期限

ForEach($servers 中的$server){ ForEach($文件中的$行){

    if($line -match $server.Name + "." -and $line -NotMatch 'replica$'){
       
        $serverInfoSheet.Cells.Item($row,$column)= $line.ToString()

    }        
}

$Column++
$serverInfoSheet.Cells.Item($row,$column)=$deploymentDate.EnforcementDeadline
    
#Check to see if space is near empty and use appropriate background colors
$range = $serverInfoSheet.Range(("A{0}"  -f $row),("G{0}"  -f $row))
$range.Select() | Out-Null

$Column = 1
$row++

}

© www.soinside.com 2019 - 2024. All rights reserved.