我试图从CSV文件中读取threatType
,threatSubtype
,threatLocation
并将该信息用于:
1)指定$storageFile
,其中包含threatType
和threatSubtype
的组件,
2)指定要下载的位置。
$storageDir = "C:\Threat Intelligence\Zeus"
$webclient = New-Object System.Net.WebClient
$intelSource = "C:\Threat Intelligence\sources.csv"
import-Csv $intelSource | ForEach-Object {
$storagefile = "${storageDir}\${_.threatType}_${_.threatSubtype}_$(get-date -f MM-dd-yy-ss).csv"
$url = $_.threatLocation
foreach ($property in $intelSource)
{
$webclient.DownloadFile($url,$storagefile)
}
}
除了设置$storageFile
的值之外,脚本的每个其他部分都有效。我无法带来$_.threatType
或$_.threatSubtype
。
所需的文件名输出+路径为:C:\Threat Intelligence\Zeus\zeus_ip_11-02-15-39.csv
其中"zeus"
和"ip"
分别为threatType
和threatSubtype
。
答案 0 :(得分:0)
99%的修正费用归Matt所示:
$storageDir = "C:\Threat Intelligence\Zeus\"
$webclient = New-Object System.Net.WebClient
$intelSource = "C:\Threat Intelligence\sources.csv"
import-Csv $intelSource | ForEach-Object {
$storageFile = "$($storageDir)\$($_.threatType)_$($_.threatSubtype)_$($(get-date -f MM-dd-yy-ss)).csv"
$url = $_.threatLocation
$webclient.DownloadFile($url,$storageFile)
}
更改:已删除第二个ForEach
,$storageFile =
已更改为在所有变量之前使用$(
(通过https://jrich523.wordpress.com/2011/07/01/powershell-working-with-strings/发现此方法)