I am new to PowerShell. I am writing a script to calculate the Network ID and Broadcast Address using the IP Address and Subnet Mask. I am struggling with the logical and. My script asks the user for the IP and Subnet, then converts the prompt to binary. I then use a for loop to perform the logical and. However, the '.' is part of the input in the for loop, so the operation does not work. Can I remove the '.' for the purpose of the operation? Some of my code is pasted below. I'm sure there is a simple solution, but I am a beginner, so any help is appreciated. Thanks!
$input = Read-Host "Would you like to calculate the Network Address? (Y for yes, N for no)"
if ($input -eq 'Y')
{
$ipAddress = Read-Host "Please enter your IP Address"
$ipBin = $ipAddress -split '\.'| ForEach-Object {[System.Convert]::ToString($_,2).PadLeft(8, '0')}
$ipBinJoin = $ipBin -join '.'
$subnetMask = Read-Host "Please enter your Subnet Mask"
$subnetBin= $subnetMask -split '\'| ForEach-object {[System.Convert]::ToString($_,2).PadLeft(8, '0')}
$subnetBinJoin = $subnetBin -join '.'
echo $ipAddress, $ipBinJoin
echo $subnetMask, $subnetBinJoin
for ($i = 0; $i -lt 32; $i++)
{
$networkIDBin = $ipBinJoin.Substring($i,1) -band $subnetBinJoin.Substring($i,1)
}