I created a Powershell script that would run in Task Scheduler to update my AWS security groups based upon my public ip address. When I run this script I get an error message which is posted below.
I would also like your help in modifying the script below to delete the old IP address when updating to the new IP address.
The script
# 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)
Error
<# Grant-EC2SecurityGroupIngress : Cannot bind parameter 'IpPermission'. Cannot create object of type "Amazon.EC2.Model.IpPermission". Object of type 'System.Management.Automation.PSObject' cannot be converted to type 'System.Collections.Generic.List`1[System.String]'. At 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 #>