0
我试图从一个CSV文件中读取threatType
,threatSubtype
,threatLocation
并利用这些信息来:使用CSV域生成保存位置论据Web客户端下载文件
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
。
'$ storagefile =“ {$ storageDir} \ {$ _。threatType} _ {$ _。threatSubtype} _ $(get-date -f MM-dd -yy-ss).csv“'为'$ webclient.DownloadFile返回'MethodInvocationException' url,$ storagefile)' – ayoungblood
可能还有其他问题。首先,我指出的代码是错误的,需要修正。 '$ storagefile'在循环中看起来是否正确? – Matt
哦。傻我。我错过了这个循环以及'foreach($ intelSource中的$ property)'应该被删除。我没有看到服务的目的。你已经循环了'$ intelSource',所以你不需要再循环它。 – Matt