Export scripted info and then turn around and import info to another script RRS feed

  • Question

  • Hello,

    I am trying to retrieve a list of servers on a subnet and then verify if they have a dhcp reservation. 

    I've found 2 scripts online that do what I need to do, I just need to tie them together.

    I'm having trouble exporting the server names gathered from the first script and importing them into the second script. It may be that I can combine them with commands in the middle of the two.

    I'd like to export the info found in this script, which is the server names in my domain:

    $strCategory = "computer" 
    $strOperatingSystem = "Windows*Server*" 
    $objDomain = New-Object System.DirectoryServices.DirectoryEntry 
    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher 
    $objSearcher.SearchRoot = $objDomain 
    $objSearcher.Filter = ("OperatingSystem=$strOperatingSystem") 
    $colProplist = "name" 
    foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} 
    $colResults = $objSearcher.FindAll() 
    foreach ($objResult in $colResults) 
        $objComputer = $objResult.Properties;  

    I'd then like to import the exported information to be included in this script to see if there is a reservation for the servers:

    $ComputerName = (Imported names from above)
    $NetAdapters = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $ComputerName | ? {$_.DHCPEnabled -eq $True -and $null -ne $_.IPAddress}
    If ($NetAdapters) {
        Foreach ($Adapter in $NetAdapters) {
            foreach ($IP in $Adapter.IPAddress) {
                $Reservation = Get-DhcpServerv4Reservation -ScopeId $IP -ComputerName $Adapter.DHCPServer | ? {$_.ScopeId -eq $_.IPAddress}
                If ($Reservation) {
                    Write-Output "$IP is reserved on $($Adapter.DHCPServer)."
                } Else {
                    Write-Output "$IP does not have a reservation."
    } Else {
        Write-Output "No DHCP Enabled NetAdapters with IPAddresses exist on host, likely Static"

    Thanks for any assistance.

    • Moved by Bill_Stewart Wednesday, May 9, 2018 2:44 PM This is not "scripts on demand"
    Wednesday, February 28, 2018 4:04 PM


All replies