export a lease

Hello everybody,

the script was make for a Windows server 2012 and is use to export a lease from a DHCP in a MySQL database

i would know when is a possibility to convert this script to use him of a server 2008 R2 ?

$connectionString = "server=localhost;uid=user;pwd=user;database=arpwatch;Allow User Variables=true;Pooling=false;"
$connection = New-Object MySql.Data.MySqlClient.MySqlConnection
$connection.ConnectionString = $connectionString
Get-DhcpServerv4Lease -ScopeId -ComputerName winserver |
Select-Object -Property ClientId, IPAddress |
Export-Csv -NoTypeInformation -Path C:\Users\Administrateur\mysql.csv

$sql = @'
    LOAD DATA LOCAL INFILE 'C:\\Users\\Administrateur\\mysql.csv'
    INTO TABLE dhcp
$command = New-Object MySql.Data.MySqlClient.MySqlCommand($sql, $connection)
$rowsAffected = $command.ExecuteNonQuery();

Thanks for your helping

The DHCP server on 2008R2 doesn’t have PowerShell cmdlets, which means you’re not going to be able to easily convert it.

It looks like the DHCP commands run CIM internally, which means in theory you could just do WMI/CIM directly against a 2008R2 server. However, I don’t know if DHCP in 2008R2 actually supports WMI/CIM. That may have been added in 2012 specifically to enable PowerShell, and if that’s the case, then a conversion would be impossible.

Generally speaking, PowerShell is a lot less useful for management on 2008R2, because 2008R2 doesn’t have the needed commands or the underlying command support layers.

Thanks for the answer !

i have a question what mean you with WMI/CIM ? ( i begin with powershell and windows server ) ?

the only solution I’ve found is this command :

netsh dhcp server scope show clients > c:\dhcp.csv

I have to look how to keep only the adress ip, and mac from the file text now with mysql