Search code examples
powershellmac-addressdhcpwindows-server-2016

How can I stop my MAC address from being seen as a number?


I'm using a cmdlet to create a policy of allowed MAC inside a scope of the Windows Server 2016 DHCP service.

I have a C# code that generates the script with all the info and it's legit, the MAC addresses are correct, but PowerShell turns out to "translate" some address, like 8634971886e5 into 863497188600000.

The generated statement is:

Add-DhcpServerv4Policy -Name Test -Condition OR -ScopeId 127.0.0.1 -MacAddress EQ,8634971886e5

If I quote it, it'll say that the operator EQ is missing.

Add-DhcpServerv4Policy -Name Test -Condition OR -ScopeId 127.0.0.1 -MacAddress "EQ,8634971886e5"

Solution

  • So according to the documentation for Add-DhcpServerv4Policy -MacAddress is looking for a string array. The example they give is much the same as your own.

    PS C:\> Add-DhcpServerv4Policy -Name HyperVPolicy -Condition OR -MacAddress EQ,00155D*,000569*
    

    However, as you have seen some of your MACs are being seen as numbers since they are not quoted/typed as strings. Comments have been telling you to quote the string but I think that is being done incorrectly. Don't quote the entire string but it's individual elements so that it is a string array. From your comments

    Add-DhcpServerv4Policy -Name Test -Condition OR -ScopeId 127.0.0.1 -MacAddress "EQ,8634971886e5"
    

    -MacAddress is being sent one string. The first element is not a comparator hence the error you were getting.

    Instead it should be...

    Add-DhcpServerv4Policy -Name Test -Condition OR -ScopeId 127.0.0.1 -MacAddress "EQ","8634971886e5"
    

    Your workaround obviously works fine but I wanted you to know what other were trying to tell you.