If you have to consolidate more databases, perhaps you also have to copy manual set data to the new database. You can do this with following steps:

1) Ensure that all devices from the old db exist in the new one (e.g. by scanning your network again)

2) Go to your source database, create a query (base table: Device) which includes “Device.Name” and all your custom properties you want to transfer (AssetCustom.*)

3) Export this data to csv (via Print->View … ->Export to…) – Keep your delimiter in mind (script works with “;” by default)

4) Save code below into a ImportCustomProperties.ps1 file

5) Open PSC.exe (from the target LOGINventory installation!!!) and execute following line: [path]\ImportCustomProperites.ps1 [path]\exportedproperties.csv

Now the script copies each property including it’s value to the target database step by step.

Script:

#############################################
# ImportCustomProperties.ps1
# ——————-
# Use this script, to add manual properties to specific assets.
# The script reads lmc exported csv-files containing
#    – device name
#    – property names
#
# separated by ‘;’.
#
# Example for input file line:
#    Device.Name;Custom.myDateProperty;Custom.myStringProperty;…
#   PC1;23.12.2015;TestString
#   PC2;21.12.2015;TestString2
# Schmidt’s LOGIN, 2015
# Script version:  1.0
#############################################

# Read List
param([string]$file)
$list = Get-Content $file | ConvertFrom-Csv -Delimiter “;”

# Call the LOGINventory6 scripts:
# [LOGINventory]\PSC.exe -file “[path]\[scriptname].ps1”

# Save current path, to restore at the end …
$savePath=$PWD

$keyProperty = “Device.Name”
$valuePropertyPrefix = “Custom.”

$list | foreach {
$o = $_;
$deviceName = $_.PSObject.Properties[$keyProperty].Value;
write-host($deviceName);

$valueProps = ($_ | Get-Member -MemberType NoteProperty).Name | Where {$_ -like $valuePropertyPrefix+”*”}
$valueProps | foreach {
$value = $o.PSObject.Properties[$_].Value;
if ($value) {
$customProperty = $_.ToString().Replace($valuePropertyPrefix, “”)
Set-LiCustomProperty -Name $customProperty -Value $value -AssetName $deviceName

Write-Host($customProperty)
Write-Host($value)
}
}
}

cd $savePath

Tagged on:     

Leave a Reply