我有一个csv,它有3列:
Name/desc Start IPv4 address End IPv4 Address
最终,我需要循环浏览这个csv,并在powershell中执行以下操作:
New-AzSqlServerFirewallRule -ResourceGroupName "ResourceGroup01" -ServerName "Server01" -FirewallRuleName "Rule01" -StartIpAddress "192.168.0.198" -EndIpAddress "192.168.0.199"
我熟悉python,但在powershell中却很难做到这一点。以下是我迄今为止所拥有的:
$csv = Import-Csv -Path "C:\Pathtofile"
foreach($line in $csv)
{
$properties = $line | Get-Member -MemberType Properties
for($i=0; $i -lt $properties.Count;$i++)
{
$column = $properties[$i]
$columnvalue = $line | Select -ExpandProperty $column.Name
if($column.name -contains 'Start'){
#write($column)
write($column.name)
}
write($column.name.GetType())
}
}
我的想法是首先检查列名是否包含“Start”、“End”或“name”,但我的if语句不起作用。我怀疑这是因为我试图将对象与字符串进行比较。当我写GetType()时,我看到每一行都是这样的:
IsPublic IsSerial Name BaseType
True True String System.Object
我不知道这是否意味着它是一根绳子或什么?它看起来像是一个字符串,但我不明白为什么我的if语句不起作用。
我想,如果我能克服这一点,我可能会设置变量,并在AzSqlServerFirewallRule命令中使用它们。