如何在我的Powershell脚本中添加附件?

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

我想在脚本中添加一个追加。因此,如果它崩溃了,它给我的数据到此为止,并且不会像打印任何东西一样打印。现在,该脚本的用途是按名称和日期过滤列表。之后,它将删除黑名单上的所有名称,并且仅包含我输入的月份中的条目

[xml]$config = Get-Content -Path 'C:\Users\DZimmermann\Desktop\EVIM.Script\EVIM-Config.xml'
[xml]$blacklist = Get-Content -Path 'C:\Users\DZimmermann\Desktop\EVIM.Script\EVIM-Blacklist.xml'



#Names to filter
$BLN = $blacklist.Names
#Import Path
$info = Import-Csv $config.config.path.input -Delimiter ';'
$info | Format-Table
#from which month
#$dateCutoff = get-date "02.2020" -Format "MM.yyyy"
$dateCutoff = $config.config.date
$result = foreach($i in $info){
    if(-Not($blacklist -contains $i.SCAN_USER)){


        $entryDate = get-date $i.SCAN_DATE -Format "MM.yyyy"


        if($entryDate -eq $dateCutoff){
        $i
        }
    }
    Write-Host $i.SCAN_DATE
    }
    #Export path
    $result | Export-Csv $config.config.path.output -NoTypeInformation -Delimiter ';' 
$dateCutoff

我所有可更改的变量都与配置文件链接,因此您不必每次都编辑脚本。

powershell filter append
2个回答
0
投票

0
投票
[xml]$config = Get-Content -Path 'C:\Users\DZimmermann\Desktop\EVIM.Script\EVIM-Config.xml' [xml]$blacklist = Get-Content -Path 'C:\Users\DZimmermann\Desktop\EVIM.Script\EVIM-Blacklist.xml' #Names to filter $BLN = $blacklist.Names #Import Path $info = Import-Csv $config.config.path.input -Delimiter ';' $info | Format-Table #from which month #$dateCutoff = get-date "02.2020" -Format "MM.yyyy" $dateCutoff = $config.config.date $result = foreach($i in $info){ if(-Not($BLN -contains $i.SCAN_USER)){ $entryDate = Get-Date $i.SCAN_DATE -Format "MM.yyyy" if($entryDate -eq $dateCutoff){ $i } } $result | Out-File $config.config.path.output Write-Host $i $config.config.path.output + "\" + $info | Out-File -Append $config.config.path.output }
© www.soinside.com 2019 - 2024. All rights reserved.