If we from the beginning tried to link all systems by serial numbers of physical devices, for example esxi server has consistent serial number attribute in all systems like prtg (for example for this we can use prtg Tags), netbox, ilo/idrac and so on, then we can run queries and auto sync data between the systems without tiresome manually syncs (mandatory to check that entered serial numbers are unique and registered in all systems properly). When we initially normalize all systems by enriching each of  <span><a href="https://www.itforce.mn/index.php/2021/11/30/draft-of-powershell-script-to-sync-information-between-prtg-netbox-ilo-idrac-and-vcsa-just-to-show-the-main-ideas/" class="readmore">Continue reading &rarr;</a></span>{"id":1666,"date":"2021-11-30T17:50:32","date_gmt":"2021-11-30T09:50:32","guid":{"rendered":"https:\/\/www.itforce.mn\/?p=1666"},"modified":"2021-11-30T22:14:54","modified_gmt":"2021-11-30T14:14:54","slug":"draft-of-powershell-script-to-sync-information-between-prtg-netbox-ilo-idrac-and-vcsa-just-to-show-the-main-ideas","status":"publish","type":"post","link":"https:\/\/www.itforce.mn\/index.php\/2021\/11\/30\/draft-of-powershell-script-to-sync-information-between-prtg-netbox-ilo-idrac-and-vcsa-just-to-show-the-main-ideas\/","title":{"rendered":"Draft of powershell script to sync information between prtg, netbox, ilo\/idrac and vcsa, just to show the main ideas."},"content":{"rendered":"<p>If we from the beginning tried to link all systems by serial numbers of physical devices, for example esxi server has consistent serial number attribute in all systems like prtg (for example for this we can use prtg Tags), netbox, ilo\/idrac and so on, then we can run queries and auto sync data between the systems without tiresome manually syncs (mandatory to check that entered serial numbers are unique and registered in all systems properly). When we initially normalize all systems by enriching each of them by proper serial numbers, then we can create programmatically (using for example powershell modules) integrity controls, for example comparing\/matching data from DNS\/DHCP, from IPAM, from Netbox, SystemCenter ConfMgr, Active Directory, VeeamBR and\u00a0 so on to create email alerts\/reminders\/notifications and so on (for example to notify absence of the information in one of systems, mismatching information, wrong information and so on)<\/p>\n<p>Below you can find the sample of the script, which reads information from netbox and prtg and writes it into custom attributes of esxi in vcsa ( considered that vcsa is named as\u00a0 \u201cvcsa.itforce.local\u201d; netbox is named as \u201cnetbox.itforce.local\u201d; prtg is named as &#8220;prtg.itforce.local&#8221;; esxi should be installed mandatory from customized image with support of ilo\/idrac vibs) Considered that custom attributes are named as:<\/p>\n<ul>\n<li>0-hostname<\/li>\n<li>00-site<\/li>\n<li>01-rack<\/li>\n<li>02-rack-position<\/li>\n<li>03-serial-number<\/li>\n<li>04-netbox-device<\/li>\n<li>05-ilo-idrac<\/li>\n<li>06-prtg-link<\/li>\n<\/ul>\n<p>Prerequisites:<\/p>\n<ol>\n<li>the computer &#8220;aaa&#8221; from which we can run the below script should have all needed network accesses to all systems like PRTG, Netbox, Vcsa and so on<\/li>\n<li>&#8220;aaa&#8221; should have installed powercli, installed prtgapi and powerbox powershell modules<\/li>\n<li>the below script can be placed into Scheduled Tasks (mandatory to tick \u201crun with highest privileges&#8221;)<\/li>\n<\/ol>\n<p>To pre-create custom attributes for each esxi in your vcsa:<\/p>\n<pre>connect-viserver vcsa.itforce.local\r\nNew-CustomAttribute -TargetType \"vmhost\" -Name \"0-hostname\"\r\nNew-CustomAttribute -TargetType \"vmhost\" -Name \"00-site\"\r\nNew-CustomAttribute -TargetType \"vmhost\" -Name \"01-rack\"\r\nand so on<\/pre>\n<pre>.'C:\\Program Files (x86)\\VMware\\Infrastructure\\PowerCLI\\Scripts\\Initialize-PowerCLIEnvironment.ps1'\r\nconnect-viserver vcsa.itforce.local\r\n\r\n#replace \"xxx\", \"yyy\", \"itforce\\prtguser\" by real secrets; replace all server names for prtg, netbox, vcsa and so on\r\n$prtg_password_plaintext=\"xxx\"\r\n$netbox_api_token_key=\"yyy\"\r\nImport-Module prtgapi\r\n$cred=\"itforce\\prtguser\"\r\n$prtg_password = ConvertTo-SecureString -String $prtg_password_plaintext -AsPlainText -Force\r\n$prtg_cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $cred,$prtg_password\r\nconnect-prtgserver -credential $prtg_cred -server prtg.itforce.local\r\n\r\nimport-module powerbox\r\n$Pass = ConvertTo-SecureString -String $netbox_api_token_key -AsPlainText -Force\r\nConnect-nbAPI -Token $Pass -APIurl http:\/\/netbox.itforce.local\/api\r\n\r\n$failed=$null\r\n$vmhostserials= Get-VMHost |Select-Object Name,NetworkInfo,@{N=\"SerialNumber\";E={(Get-VMHostHardware -vmhost $_).SerialNumber}}, @{ N=\"OutOfBandIP\";E={(Get-VMHostWSManInstance -VMHost $_ -ignoreCertFailures -class OMC_IPMIIPProtocolEndpoint).IPv4Address}}\r\n\r\n\r\nforeach ($item in $vmhostserials)\r\n{\r\n$fromnetbox=$null\r\n$sn=$item.SerialNumber.trim()\r\n$fromnetbox=Get-nbDevice -query @{serial=$sn}\r\n\r\n$site=$fromnetbox.site\r\n$rack=$fromnetbox.rack\r\n$position=$fromnetbox.position\r\n$netboxid=$fromnetbox.id\r\n$iloidrac=$item.OutOfBandIP\r\n$fqdn=$item.NetworkInfo\r\n$netboxlink=\"http:\/\/netbox.itforce.local\/dcim\/devices\/\"+$netboxid+\"\/\"\r\n\r\n$site\r\n$rack\r\n$position\r\n$sn\r\n$netboxid\r\n$iloidrac\r\n$netboxlink\r\n\r\n$fromprtg=get-device *$sn*\r\n$prtgid=$fromprtg.id\r\n$prtglink=\"https:\/\/prtg.itforce.local\/device.htm?id=\"+$prtgid\r\n\r\n$prtgid\r\n$prtglink\r\n\r\nTry {\r\n\r\nif ($fqdn -ne \"\"){\r\nget-vmhost $item.name | Set-Annotation -CustomAttribute \"0-hostname\" -Value $fqdn -ErrorAction Stop\r\n}\r\n\r\nif ($site -ne \"\"){\r\nget-vmhost $item.name | Set-Annotation -CustomAttribute \"00-site\" -Value $site -ErrorAction Stop\r\n}\r\nif ($rack -ne \"\"){\r\nget-vmhost $item.name | Set-Annotation -CustomAttribute \"01-rack\" -Value $rack -ErrorAction Stop\r\n}\r\nif ($position -ne \"\"){\r\nget-vmhost $item.name | Set-Annotation -CustomAttribute \"02-rack-position\" -Value $position -ErrorAction Stop\r\n}\r\n\r\nget-vmhost $item.name | Set-Annotation -CustomAttribute \"03-serial-number\" -Value $sn -ErrorAction Stop\r\n\r\nif ($netboxlink -ne \"\"){\r\nget-vmhost $item.name | Set-Annotation -CustomAttribute \"04-netbox-device\" -Value $netboxlink -ErrorAction Stop\r\n}\r\n\r\nget-vmhost $item.name | Set-Annotation -CustomAttribute \"05-ilo-idrac\" -Value $iloidrac -ErrorAction Stop\r\n\r\nif ($fromprtg.count -ne \"0\") \r\n{\r\nget-vmhost $item.name | Set-Annotation -CustomAttribute \"06-prtg-link\" -Value $prtglink -ErrorAction Stop\r\n}\r\n\r\n}\r\n\r\ncatch \r\n{\r\n\r\n$failed+=$item.vmhost.name\r\n}\r\n\r\n\r\n}\r\n\r\n\r\nwrite-host \"-----------------\"\r\nwrite-host \"script failed for below esxi:\"\r\nwrite-host $failed\r\n\r\ndisconnect-viserver vcsa.itforce.local\r\n\r\n\r\n\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":null,"protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1666","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts\/1666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/comments?post=1666"}],"version-history":[{"count":15,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts\/1666\/revisions"}],"predecessor-version":[{"id":1681,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts\/1666\/revisions\/1681"}],"wp:attachment":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/media?parent=1666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/categories?post=1666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/tags?post=1666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}