export a lease

Welcome Forums General PowerShell Q&A export a lease

This topic contains 2 replies, has 2 voices, and was last updated by

4 years, 6 months ago.

  • Author
  • #18266

    Points: 0
    Rank: Member

    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
        LINES TERMINATED BY '\r\n'
        IGNORE 1 LINES;
    $command = New-Object MySql.Data.MySqlClient.MySqlCommand($sql, $connection)
    $rowsAffected = $command.ExecuteNonQuery();

    Thanks for your helping

  • #18269

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

  • #18279

    Points: 0
    Rank: Member

    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

The topic ‘export a lease’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort