Powershell to delete the Windows Failover Cluster IP

I have some knowledge in the Powershell as SQL DBA, but not in depth. We moved to the SQL to different subnets and we need to add the new subnet , assign new IP and delete the old IP address. I got some code from the internet for adding new IP resource , and I am looking for the code to delete the IP address. Could you please help me in deleting the cluster IP address, which is in offline state. 

Here is my code to add the new IP address:

$conn_server = $env:computername
$varClusterNetworkInterface= Get-ClusterNetworkInterface | Where-Object { $_.Node -eq "$conn_server" } ## to get the network name of the current host
$newClusterIPAddress = '<<New_IP_Address>>' ## this is the input for new IP address, this is the input from my script
## adding new cluster resource along with IP Address
$varClusterResource = "Cluster IP Address Cloud " + $newClusterIPAddress ## to name the resource
$varClusterParam = Get-ClusterNetwork -name $varClusterNetworkInterface.network.name

Add-ClusterResource -Name $varClusterResource -Group 'Cluster Group' -ResourceType 'IP Address'
Get-ClusterResource -Name $varClusterResource | Set-ClusterParameter -Multiple @{ Address = $newClusterIPAddress;
Network = $varClusterParam.Name;
SubnetMask = $varClusterParam.AddressMask; }

$varClusterAlias=(Get-ClusterResource | Get-ClusterParameter | Where-Object {$_.Name -eq "Name"})[0].ClusterObject.Name
$clusterGroup = (Get-ClusterResource $varClusterAlias).OwnerGroup |select -ExpandProperty "Name"
$varDepdency = (Get-ClusterResourceDependency -Resource $varClusterAlias).DependencyExpression
$varDepdencyToSet="${varDepdency} or [${varClusterResource}]"

Set-ClusterResourceDependency -Resource $varClusterAlias -Dependency $varDepdencyToSet;

Can someone help me to deleting the highlighted IP address.. I am able to manage which IP needs to be deleted. Do we need to remove from cluster resource dependency?? 

  • can someone pls help me with deleting the IP address of a Windwos Failover Cluster.

  • I added the following my self.. Correct me if I am wrong:

    ## taking offline IP addresses 

    write-host "Checking for any resource removal..."
    $getClusterOfflineAddress = Get-ClusterResource | Where-Object { $_.ResourceType -eq "IP Address" -and $_.OwnerGroup -eq "Cluster Group" -and $_.State -eq "Offline" } | Get-ClusterParameter -Name "Address" | Select-Object ClusterObject, Value

    for ($index = 0;$index -lt $getClusterOfflineAddress.count; $index++)
    write-host "Checking network for the resource :" + $getClusterOfflineAddress[$index].ClusterObject.Name
    $getResourceNetwork = Get-ClusterResource -Name $getClusterOfflineAddress[$index].ClusterObject.Name | Get-ClusterParameter -Name "Network"
    write-host "Network is :" $getResourceNetwork.value
    write-host "IP Value is:" $getClusterOfflineAddress[$index].value
    if ($getResourceNetwork.value -notlike 'Cluster Network*' ) ## i noticed this value is different compared other resource
    write-host "Detected the resource .." + $getClusterOfflineAddress[$index].ClusterObject.Name


    If ( $removeClusterResource -ne '')
    Remove-ClusterResource -Name $removeClusterResource -Force