我创建了一个 Powershell 脚本,该脚本将在 Task Scheduler 中运行,以根据我的公共 IP 地址更新我的 AWS 安全组。当我运行此脚本时,我收到一条错误消息,该消息发布在下面。
我还希望您能帮助我修改下面的脚本,以便在更新到新 IP 地址时删除旧 IP 地址。
剧本
# to get current ip address in cidr format
$ipinfo = Invoke-RestMethod http://ipinfo.io/json
$ipinfo.ip | out-file -filepath currentip -NoNewline
$ipCidr = Add-Content -Path "currentip" -Value "/32"
# take current ip address and update the security group
# the second part I am getting an error message pasted below
$ipchange = @{ IpProtocol="tcp"; FromPort="1433"; ToPort="1433"; IpRanges=$ipCidr}
Grant-EC2SecurityGroupIngress -GroupId sg-0d28d1cbc04d5df91 -Region us-east-2 -IpPermission @($ipchange)
错误
<# Grant-EC2SecurityGroupIngress:无法绑定参数“IpPermission”。无法创建“Amazon.EC2.Model.IpPermission”类型的对象。“System.Management.Automation.PSObject”类型的对象无法转换为“System.Collections.Generic.List`1[System.String]”类型。在 C:\users\inayet\desktop\aws-amazon\scripts\runCurrentIP.ps1:15 char:93 + ... pId sg-0d28d1cbc04d5df91 -Region us-east-2 -IpPermission @($ipchange) + ~~~ ~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Grant-EC2SecurityGroupIngress], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Amazon.PowerShell.Cmdlets.EC2.GrantEC2SecurityGroupIngressCmdlet #>