diff --git a/SyncglpicomputertoitopPC.ps1 b/SyncglpicomputertoitopPC.ps1 new file mode 100644 index 0000000..097bfce --- /dev/null +++ b/SyncglpicomputertoitopPC.ps1 @@ -0,0 +1,140 @@ +$GlpiCreds = @{AppURL = "http://192.168.100.89/apirest.php";UserToken = "JSsoyIIG067IOWJG0EoJoDFtDSWs8fYgUZgVYQRo";AppToken = "4eMkSWhCanzvyOhTcVInLYhmA4c4gfdXFcCVOsRl";AuthorizationType = "user_token"} + +$salle = 'A105' + +$liste = Search-GlpiItem -ItemType "Computer" -SearchOptions ("AND",1,"contains","$salle"),("OR",2,"contains",""),("OR",4,"contains",""),("OR",5,"contains",""),("OR",37,"contains",""),("OR",40,"contains",""),("OR",46,"contains",""),("OR",48,"contains",""),("OR",17,"contains",""),("OR",111,"contains","") -Creds $GlpiCreds + +$local = Get-iTopObject -key "SELECT Location WHERE name LIKE '%A105'" -class "Location" -OutputFields "*" +$location = $local.key + +For ($i=0; $i -le $liste.Length; $i++) { +$pcglp = $liste[$i].2 + +echo $pcglp + +$liste2 = Search-GlpiItem -ItemType "Computer" -SearchOptions ("AND",1,"contains",""),("AND",2,"contains","$pcglp"),("OR",4,"contains",""),("OR",5,"contains",""),("OR",37,"contains",""),("OR",40,"contains",""),("OR",46,"contains",""),("OR",48,"contains",""),("OR",17,"contains",""),("OR",111,"contains","") -Creds $GlpiCreds + + +$modele = $liste2.40 +$mod = Get-iTopObject -key "SELECT Model WHERE name LIKE '%$modele%'" -class "Model" -OutputFields "*" + + +if (!$mod) { + Write-Host "Le modèle '$modele' ne existe pas dans iTop" + } + +$pc = Get-glpiitem -itemtype Computer -id $liste2.2 -creds $GlpiCreds +$pc_id = $pc.id +$pc_serial = $pc.serial +$name = $pc.name +if (($pc.otherserial -eq $null) -or ($pc.otherserial -eq "")) { $pcserial = 'notset' } else { $pcserial = $pc.otherserial } + +if (!$pc.manufacturers_id) { $brand = 10 } elseif ($pc.manufacturers_id -eq 1) {$brand = 106} + +if (!$pc.computermodels_id) { $model= 150 } + elseif ($pc.computermodels_id -eq 6) { + $model = 152} + elseif ($pc.computermodels_id -eq 8) { + $model = 149} + elseif ($pc.computermodels_id -eq 10) { + $model = 176} + elseif ($pc.computermodels_id -eq 1) { + $model = 175} +if (!$liste2.46) { + $os = 8 } + elseif ($liste2.46 -eq 1803) { + $os = 146} + elseif ($liste2.46 -eq 1607) { + $os = 146} + elseif ($liste2.46 -eq 1703) { + $os = 146} + elseif ($liste2.46 -eq 1709) { + $os = 146} + elseif ($liste2.46 -eq 1809) { + $os = 146} + elseif ($liste2.46 -eq 1909) { + $os = 146} +if (!$liste2.48) { + $version = 154 } + elseif ($liste2.48 -eq '10.0.17134') + { $version = 154} +if (!$liste2.37) { +$date2prod = $null +$garantie = $null +} +else + { if (($liste2.37 -eq $null) -or ($liste2.37 -eq "")) + { +$date2prod = $null +$garantie = $null + } + else + {$date2prod = $liste2.37 + $dateprod = [datetime]::parseexact($date2prod, 'yyyy-MM-dd', $null) + $datep = $dateprod.ToString('yyyy-M-d') + $garantie = $dateprod.AddYears(+5) + $garant = $garantie.ToString('yyyy-M-d') + } +} +if (!$liste2.17) { $cpu = "" } else { $cpu = $liste2.17 } +if (!$liste2.111) { $ram = "" } else { $ram = $liste2.111 } +if (!$liste2.4) { + $type = 'desktop' } + elseif ($liste2.4 -eq 'Laptop' ) { + $type = 'laptop' } + elseif ($liste2.4 -eq 'Desktop' ) { + $type = 'desktop' } + elseif ($liste2.4 -eq 'Mini Tower' ) { + $type = 'desktop' } + elseif ($liste2.4 -eq 'Precision 5820 Tower' ) { + $type = 'desktop' } + + +$pcitop = Get-iTopObject -key "SELECT PC WHERE serialnumber='$pc_serial'" -class "PC" -OutputFields "*" + +if ((!$pcitop) -or ($pcitop -eq $null) -or ($pcitop -eq "")) { + +if ((!$liste2.37) -or ($liste2.37 -eq $null) -or ($liste2.37 -eq "")) { +php -f CreatePC2-itop.php PC 2 $name $pc_serial $pcserial $location $brand $model $os $version $cpu $ram $type +} +else { +php -f CreatePC-itop.php PC 2 $name $pc_serial $pcserial $location $brand $model $os $version $date2prod $garant $cpu $ram $type + +} +} +else { + +echo $name $location $brand $model $os $version $date2prod $cpu $ram $type $garant + +if ((!$liste2.37) -or ($liste2.37 -eq $null) -or ($liste2.37 -eq "")) { +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'name'=$name} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'asset_number'=$pcserial} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'location_id'=$location} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'type'=$type} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'brand_id'=$brand} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'model_id'=$model} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'cpu'=$cpu} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'osfamily_id'=$os} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'osversion_id'=$version} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'ram'=$ram} +} +else { +echo $location $brand $model $os $version $date2prod $cpu $ram $type $garant +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'name'=$name} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'asset_number'=$pcserial} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'location_id'=$location} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'type'=$type} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'brand_id'=$brand} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'model_id'=$model} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'cpu'=$cpu} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'osfamily_id'=$os} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'osversion_id'=$version} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'ram'=$ram} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'move2production'=$date2prod} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'purchase_date'=$date2prod} +Set-iTopObject -key $pcitop.key -class "PC" -Fields @{'end_of_warranty'=$garant} +Write-Host "rien à faire" +} +} +} +