This shows you the differences between two versions of the page.
userspace:opsi2ad [2014/02/10 11:22] dkoch |
userspace:opsi2ad [2021/08/23 08:37] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== OPSI2AD ====== | ||
- | --- // | ||
- | This script synchronizes the client descriptions from OPSI to the AD. | ||
- | - You will have to store a mysql.exe binary in the same directory as the script. | ||
- | - Replace DATABASE-HOST DATABASEUSER PASSWORD DATABASE and YOUR-DOMAIN-SUFFIX to fit for your setup | ||
- | - Make sure your MySQL server listens ( bind-address in my.cnf ) | ||
- | - Run this script as Domain-Administrator on an DC | ||
- | |||
- | |||
- | |||
- | |||
- | <code powershell> | ||
- | # This script synchronizes the client descriptions from OPSI to the AD | ||
- | |||
- | # Connect to the MYSQL of OPSI and crete a csv with $hostId and $description | ||
- | echo " | ||
- | chcp 850 | ||
- | echo "SET NAMES ' | ||
- | ./mysql.exe --default-character-set=utf8 -hDATABASE-HOST -uDATABASEUSER -pPASSWORD -DDATABASE > .output.sql | ||
- | |||
- | # Convert SQL output to valid CSV output | ||
- | (Get-Content .output.sql ) | Foreach-Object { | ||
- | $_ -replace ' | ||
- | } | Set-Content -encoding utf8 .output.csv | ||
- | |||
- | echo " | ||
- | # Load CSV and transform values for $hostId and $description | ||
- | Import-Csv ./ | ||
- | ForEach-Object { | ||
- | $hostId += $_.hostId.ToUpper().Replace(" | ||
- | $description += $_.description | ||
- | |||
- | # If $description is NOT empty or null | ||
- | if (!([string]:: | ||
- | # If $hostId is found in AD-Backend | ||
- | if ($hostou=(dsquery computer domainroot -name " | ||
- | # If $hostId has NOT same $description yet | ||
- | if (!(dsquery computer domainroot -name " | ||
- | $olddescription=(dsget computer " | ||
- | $olddescription= $olddescription.Trim() | ||
- | |||
- | echo " | ||
- | dsmod computer $hostou -desc " | ||
- | |||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | $hostOu = @() | ||
- | $hostid=@() | ||
- | $description = @() | ||
- | $objComputer= @() | ||
- | } | ||
- | </ |