SubClient Status POD5_vcprd01 POD4_vcprd01 POD15_VCPRD01_New POD11_2_vcprd01 POD11_1_vcprd01 POD12_vcprd01 POD13_vcprd01_new POD10_vcprd01_NEW
我正在尝试删除_new
&上表中的_New
是CSV格式。我写了下面的剧本:
$report = @()
$Pod_SC = Import-csv "above table"
foreach($Podclient in $pod_sc)
{
$Client = $Podclient.Subclient
$Subclient = $Client.Substring(0,$Client.IndexOf('_N'))
$Status = $Podclient.Status
$object = New-Object -TypeName PSobject
$object | Add-Member -MemberType NoteProperty -Name "Subclient" -Value $SubClient
$object | Add-Member -MemberType NoteProperty -Name "Status" -Value $Status
$report += $object
}
但它不起作用。预期的产出是
SubClient Status POD5_vcprd01 POD4_vcprd01 POD15_VCPRD01 POD11_2_vcprd01 POD11_1_vcprd01 POD12_vcprd01 POD13_vcprd01 POD10_vcprd01
答案 0 :(得分:0)
只需将其视为文字替换,如果您使用不区分大小写的ireplace
,则可以同时处理_New
和_new
。
(Get-Content file.csv) -ireplace "_new","" | Set-Content file.csv
您实际上只能使用-ireplace "_new"
,但如果您想要替换而不是删除语法,则与我的示例-ireplace "_new","_old"