title: Powershell Script to Update AWS Security Groups Based Upon Dynamic IP Error
body: <p>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.</p>
  
  <p>I would also like your help in modifying the script below to delete the old IP address when updating to the new IP address.</p>
  
  <p><strong>The script</strong></p>
  
  <pre><code># 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)
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>&lt;# 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
    #></p>
  </blockquote>