User Tools

Site Tools


userspace:opsi2ad

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
userspace:opsi2ad [2014/02/10 11:15]
dkoch
userspace:opsi2ad [2021/08/23 08:37] (current)
Line 2: Line 2:
  --- //[[koch.daniel.89@googlemail.com|dkoch]] 2014/02/09 12:15//  --- //[[koch.daniel.89@googlemail.com|dkoch]] 2014/02/09 12:15//
 This script synchronizes the client descriptions from OPSI to the AD. 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.  
  
 +  - You will have to store a mysql.exe binary in the same directory as the script. 
 +  - Replace >DATABASE-HOST< >DATABASEUSER< >PASSWORD< >DATABASE< (near mysql.exe) and >YOUR-DOMAIN-SUFFIX< (near ForEach) to fit for your setup
 +  - Make sure your MySQL server listens ( bind-address in my.cnf ) 
 +  - Execute this script as Domain-Administrator on an DC
  
 +
 +
 +This Script requires Powershell 3 
 <code powershell> <code powershell>
 # This script synchronizes the client descriptions from OPSI to the AD # This script synchronizes the client descriptions from OPSI to the AD
  
 +$timestamp=Get-Date -format u
 # Connect to the MYSQL of OPSI and crete a csv with $hostId and $description # Connect to the MYSQL of OPSI and crete a csv with $hostId and $description
 echo "Getting information from OPSI-Backend..." echo "Getting information from OPSI-Backend..."
 chcp 850 chcp 850
 echo "SET NAMES 'cp850' ; select hostId, description from HOST" | ` echo "SET NAMES 'cp850' ; select hostId, description from HOST" | `
-./mysql.exe --default-character-set=utf8 -hDATABASE-HOST -uDATABASEUSER -pPASSWORD -DDATABASE > .output.sql+./mysql.exe --default-character-set=utf8 -h>DATABASE-HOST-u>DATABASEUSER< -p>PASSWORD< -D>DATABASE< > .output.sql
    
 # Convert SQL output to valid CSV output # Convert SQL output to valid CSV output
Line 23: Line 30:
 Import-Csv ./.output.csv -encoding utf8 -Delimiter ";"  |` Import-Csv ./.output.csv -encoding utf8 -Delimiter ";"  |`
     ForEach-Object {     ForEach-Object {
-        $hostId += $_.hostId.ToUpper().Replace(".WKK-INTRA.NET","")+        $hostId += $_.hostId.ToUpper().Replace(".>YOUR-DOMAIN-SUFFIX<","")
         $description += $_.description         $description += $_.description
  
Line 35: Line 42:
  $olddescription= $olddescription.Trim()  $olddescription= $olddescription.Trim()
   
- echo "Updating $hostId with description: `"$description`" was `"$olddescription`"" >> log+ echo "[$timestamp] Updating $hostId with description: `"$description`" was `"$olddescription`"" >> opsi2ad.log
  dsmod computer $hostou -desc "$description"  dsmod computer $hostou -desc "$description"
  
userspace/opsi2ad.1392030949.txt.gz ยท Last modified: 2021/08/23 08:37 (external edit)