Closed BaffledJimmy closed 4 years ago
Update - I've worked out that it is due to an error within the Test-Subnet function, I'll investigate that now :).
Update 2 - looks to be because PS v2 doesn't support bitshift / shift left functions etc.
Thanks for figuring that out @BaffledJimmy, ill have to take a look at alternative options.
I just bashed my head against this as well. My fix:
function BitShift {
param(
[Parameter(Mandatory=$True,Position=0)]
[int]$x,
[Parameter(ParameterSetName='Left')]
[int]$Left,
[Parameter(ParameterSetName='Right')]
[int]$Right
)
$shift = If($PSCmdlet.ParameterSetname -eq 'Left')
{
$Left
}
else
{
-$Right
}
return [Math]::Floor($x * [Math]::Pow(2, $shift))
}
# Source: http://www.padisetty.com/2014/05/powershell-bit-manipulation-and-network.html
# Notes: Changed name from checkSubnet to Test-Subnet (Approved Verbs)
function Test-Subnet ([string]$cidr, [string]$ip)
{
$network, [int]$subnetlen = $cidr.Split('/')
$a = [uint32[]]$network.split('.')
[uint32] $unetwork = (BitShift $a[0] -Left 24) + (BitShift $a[1] -Left 16) + (BitShfit $a[2] -Left 8) + $a[3]
$mask = BitShift (-bnot [uint32]0) -Left (32 - $subnetlen)
$a = [uint32[]]$ip.split('.')
[uint32] $uip = (BitShift $a[0] -Left 24) + (BitShift $a[1] -Left 16) + (BitShift $a[2] -Left 8) + $a[3]
$unetwork -eq ($mask -band $uip)
}
Sorry for the lack of PR, feel free to shove it in at some point :)
No worries, thanks so much for the help!
Just an FYI, this appears to be a clone of #32. There's an open PR (#33) that was filed to fix this issue.
I think the latest version is now CLR v2 compliant so this can be closed :)
Hi there,
When trying to import PowerUpSQL into a powershell -version 2 session, the user receives the following message:
I'll have a look at working out the exact error line, but first inspection seems to be PS interpreting a '-' as a mathematical symbol rather than a hyphen.
Thanks :)