powershell - How can I parse an IP address
问题描述
I have to parse to get an IP address.
$Currentpath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$CheminCSV = $currentpath + '\LesIP.csv'
$csv = Import-Csv $CheminCSV
$MyIPS = $csv | select IP
$MyHostnames = $csv | select HostName
Write-Host($MyIPS[1])
The actual results are:
@{IP=192.168.1.10}
and I expect:
192.168.1.10
解决方案
This is not a parsing issue. Your CSV has a header for "IP". If you import this CSV, you get an object with a property "IP", which you assign to $MyIPS
.
You can get your expected output by $MyIPS[1].IP
. Or you simple change your select
(i.e. select-object -Property
) to Select-Object -ExpandProperty IP
.
推荐阅读
- javascript - 类型错误,无法读取未定义的属性“地图”
- spring - 如何在春季批处理中在多个 ItemProcessor 运行之间共享价值?
- python - DJANGO 获取 sql 中的对象,例如 join
- c++ - 可能的动态分配问题
- javascript - 从 TypeScript 功能的角度来看,Vue.js 3 是否可以实现基于类的语法?
- postgresql - 在 Postgres 12.3 中,ENABLE REPLICA TRIGGER 和 ENABLE ALWAYS TRIGGER 有什么不同吗?
- c# - 选择列表中定义为枚举的项目C#
- android - Android替换选项卡布局和viewPager2中的当前片段
- python - 在熊猫数据框中按字母顺序排序
- racket - 映射到嵌套列表,函数应用于引用