Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Veyon Community Forum

  1. Home
  2. Success stories & community contributions
  3. Script PowerShell for export DHCP MAC address and import to Active Directory

Script PowerShell for export DHCP MAC address and import to Active Directory

Scheduled Pinned Locked Moved Success stories & community contributions
3 Posts 3 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joel
    wrote on last edited by
    #1

    I just finished a powershell script to extract known MAC addresses from the DHCP server and import them into the Active Directory.

    The search for the range is automatic and before executing the script as it is you are invited to try it by commenting the line n°20 which starts with Set-ADComputer

    If you find improvements to be made, please indicate this by answering this subject.

    # Extraction de l'étendue	
    $scope=Get-DhcpServerv4Scope | Select-Object ScopeId | ForEach-Object {$_.ScopeId} | ForEach-Object {$_.IPaddressToString}
    
    Write-Host "L'étendue est $scope"
    
    # Liste des stations par nom
    Get-ADComputer -Filter {OperatingSystem -NotLike "*server*"} -Property Name | select-object -expandproperty name | ForEach-Object {
    
    	# Récupération du nom de la station
    	$AD_station="$_"
    	
    	# Extraction de l'adresse MAC selon le nom de la station
    	$DHCP_MAC=Get-DhcpServerv4Lease -computername $env:computername -allleases -ScopeId $scope | Where-Object {$_.HostName -like "*$AD_station*"} | select-object -expandproperty ClientID
    
    	#Write-Host "L'adresse MAC de $AD_station est $DHCP_MAC"
    
    	# Ajout de l'adresse MAC dans l'attribut wWWHomePage
    	if($DHCP_MAC) {
    		# Set-ADComputer à commenter pour vos tests
    		Set-ADComputer $AD_station -HomePage $DHCP_MAC
    		Write-Host "L'adresse MAC $DHCP_MAC à été ajoutée dans l'AD à l'attribut wWWHomePage de la station $AD_station"
    	}
    }
    
    1 Reply Last reply
    0
    • X Offline
      X Offline
      xco
      wrote on last edited by
      #2

      Hi ! I just replaced the second line with $scope="172.16.0.0" because the other scopes concern dhcp relay and I had many errors.
      Nice work, thank you !

      W 1 Reply Last reply
      0
      • W Offline
        W Offline
        wWWHomePage
        replied to xco on last edited by
        #3

        @xco

        I made a small edit on the script, now it can be used with more than one scope in the DHCP server.

        # Extraction de l'étendue	
        $scope=Get-DhcpServerv4Scope | Select-Object ScopeId | ForEach-Object {$_.ScopeId} | ForEach-Object {$_.IPaddressToString}
        
        Write-Host "L'étendue est $scope"
        
        
        for ($i=0; $i -lt $scope.length; $i++){ 
        
        # Liste des stations par nom
        Get-ADComputer -Filter {OperatingSystem -NotLike "*server*"} -Property Name | select-object -expandproperty name | ForEach-Object {
        
        	# Récupération du nom de la station
        	$AD_station="$_"
        	
        	# Extraction de l'adresse MAC selon le nom de la station
        	$DHCP_MAC=Get-DhcpServerv4Lease -computername $env:computername -allleases -ScopeId $scope[$i] | Where-Object {$_.HostName -like "*$AD_station*"} | select-object -expandproperty ClientID
        
        	#Write-Host "L'adresse MAC de $AD_station est $DHCP_MAC"
        
        	# Ajout de l'adresse MAC dans l'attribut wWWHomePage
        	if($DHCP_MAC) {
        		# Set-ADComputer à commenter pour vos tests
        		Set-ADComputer $AD_station -HomePage $DHCP_MAC
        		Write-Host "L'adresse MAC $DHCP_MAC à été ajoutée dans l'AD à l'attribut wWWHomePage de la station $AD_station"
        	}
        }
        }
        
        1 Reply Last reply
        0

        Powered by NodeBB | Contributors
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups