none
Get-DhcpServerv4Lease not recognized RRS feed

  • Question

  • I have been trying every way I know how to get this to run and im not making any ground.  

    I just want to write a script that will connect to the dhcp server and save a report of all the clients ip addresses that start with the hostname "Player"

    New-PSSession -ComputerName DHCP-Server
    Invoke-Command {Get-DhcpServerv4Lease -ScopeId 192.168.0.0 | where{$_.HostName -like 'Player*'} | ft IP*,Host* -auto > \\group\players\Report.txt}

    If I run the commands separately, all seems to work fine, but when I put them together in a .ps1 file I get the following error:
    The term 'Get-DhcpServerv4Lease' is not recognized as the name of a cmdlet, fun
    ction, script file, or operable program. Check the spelling of the name, or if 
    a path was included, verify that the path is correct and try again.
    At C:\Users\mmaus\TruSignIPReport.ps1:2 char:38
    + Invoke-Command {Get-DhcpServerv4Lease <<<<  -ScopeId 192.168.0.0 | where{$_.Ho
    stName -like 'Player*'} | ft IP*,Host* -auto > \\group\playertrusign\Report
    .txt}
        + CategoryInfo          : ObjectNotFound: (Get-DhcpServerv4Lease:String) [ 
       ], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

    Monday, August 8, 2016 4:54 PM

Answers

  • Im trying to run the script from a Windows 7 machine.  Was only able to get the Get-Dhcp... command to work by running New-Session I also tried with Open-Session
    Monday, August 8, 2016 5:33 PM

All replies

  • Why do you need a session? That cmdlet has a -ComputerName parameter to specify the DHCP server name (take a look at the documentation).


    PS C:\> Get-DhcpServerv4Lease -ComputerName DHCP-Server -ScopeID 192.168.0.0 ...


    -- Bill Stewart [Bill_Stewart]

    Monday, August 8, 2016 4:57 PM
    Moderator
  • Im trying to run the script from a Windows 7 machine.  Was only able to get the Get-Dhcp... command to work by running New-Session I also tried with Open-Session
    Monday, August 8, 2016 5:33 PM