无法使用 PowerShell 从字符串数组中循环项目

9009

我有以下代码,但无法使用 PowerShell 循环这些项目。

$ipAddress = @('107.20.253.26', '107.20.178.220', '8.8.8.8')

for($i=0; $i -le $ipAddress.count; $i++) {

    $resolve = nslookup $i | Format-list
    $resolve | Out-File $resolveFile

}
G42

对我来说,这很好地循环了 IP。尽管使用foreach.
并删除Format-Table; 它在写入主机时很有用,但只是将nslookup结果转换为Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData数据类型。
使用-AppendwithOut-File避免覆盖以前的结果。

$ipAddress = @('107.20.253.26', '107.20.178.220', '8.8.8.8')

foreach($ip in $ipAddress) {

    # remove Format-Table
    $resolve = nslookup $ip

    # Add Append flag so that you are not overwriting previous contents on each loop
    $resolve | Out-File $resolveFile -Append

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Powershell在字符串中搜索反斜杠

使用PowerShell无法将字符串解析为对象

使用PowerShell在JQ中的字符串文字

如何使用多个字符的字符串在PowerShell中“拆分”字符串?

如何使用Powershell计算文件中的连续字符串?

使用Powershell从字符串获取键值

如何在数组中(在Powershell中)使用数字字符串进行操作?

如何使用Powershell在数组中获取特定字符串?

使用powershell在数组字符串中创建换行符

无法使用Powershell使用Xpath循环XML

使用Powershell从变量中搜索字符串

使用while循环替换Powershell多字符串

使用powershell解析字符串

使用Powershell在字符串中插入空格?

使用RegEx替换PowerShell字符串

PowerShell使用RegEx分割字符串

使用字符串替换在Powershell中插入字符串“ $ _”?

使用For Each循环在数组中添加字符串

使用PowerShell在文件名中搜索字符串

使用 PowerShell 操作对象中的字符串值

数组中的 PowerShell 字符串变量到数组变量

在 PowerShell 中不使用正则表达式检查数组的项是否包含在字符串中

如何使用PowerShell从字符串中读取变量?

使用 PowerShell 查找单词或字符串

使用 powershell 在文件名中附加字符串

使用通配符在字符串中查找字符串(Powershell)

无法从 PowerShell 中的路径获取子字符串

无法从 powershell 中的数组中删除字符串

Powershell - 使用数组中的字符串从 JSON 获取值