├── .gitignore ├── posh-itop.psd1 ├── README.md └── itop.psm1 /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /posh-itop.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonnyt/posh-itop/HEAD/posh-itop.psd1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # posh-itop 2 | 3 | A PowerShell wrapper for Combodo's iTop CMDB 4 | 5 | ## Requirements 6 | 7 | * iTop version 2.0.2 (REST API 1.1) or higher 8 | * Powershell Core 6 or higher 9 | 10 | ## Usage 11 | 12 | ```PowerShell 13 | Import-Module posh-itop 14 | Get-Command -Module posh-itop 15 | ``` 16 | 17 | ## Notes 18 | 19 | If you want to use this please look at the following two cmdlets first 20 | 21 | * Get-iTopObject 22 | * GenerateAndSendRequest 23 | 24 | Those are the main wrappers for the web services calls. The JSON returned from the iTop rest service is wrapped up in a nice PowerShell object for consumption and for feeding into other cmdlets. 25 | 26 | MySQL is required when using the data synchronization feature of iTop. 27 | 28 | This is designed to be an easy to use PowerShell wrapper for the iTop REST API. It's currently most useful for the CMDB (Configuration Management) and Service Management modules in iTop because that's all we are using. It can also invoke the data synchronization routines required when automating your CMDB. -------------------------------------------------------------------------------- /itop.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | 3 | Requires MySql libraries to be imported first when using the Data Synchro functions, see posh-mysql 4 | 5 | #> 6 | 7 | Function Get-iTopVirtualDeviceVolume { 8 | <# 9 | .Synopsis 10 | Get volume information for a virtual device (Virtualmachine, Hypervisor, Farm) 11 | 12 | .Description 13 | Get volume information for a virtual device (Virtualmachine, Hypervisor, Farm) 14 | 15 | .Parameter authName 16 | Logon for the iTop web service 17 | 18 | .Parameter authPwd 19 | Password for the iTop web service 20 | 21 | .Parameter uri 22 | uri for the iTop web service 23 | 24 | .Example 25 | Get-iTopVirtualDeviceVolume -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 26 | 27 | .Example 28 | Get-iTopVirtualDeviceVolume -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' -oqlFilter "WHERE name = 'MySQL'" 29 | 30 | #> 31 | 32 | [CmdletBinding(DefaultParameterSetName='All')] 33 | Param( 34 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 35 | [Parameter(Mandatory=$True)][string]$uri, 36 | [Parameter(ParameterSetName='name',Mandatory=$False)][string]$virtualDeviceName, 37 | [Parameter(ParameterSetName='id',Mandatory=$False)][string]$virtualDeviceID, 38 | [Parameter(ParameterSetName='oql',Mandatory=$False)][string]$oqlFilter, 39 | [Parameter(ParameterSetName='oql',Mandatory=$False)][string]$outputFields='*' 40 | ) 41 | 42 | switch($PSCmdlet.ParameterSetName) 43 | { 44 | 'name'{Get-iTopObject -objectClass 'lnkVirtualDeviceToVolume' -oqlFilter "WHERE virtualdevice_name = '$virtualDeviceName'" -ouputFields $outputFields -uri $uri -credentials $credentials} 45 | 'id' {Get-iTopObject -objectClass 'lnkVirtualDeviceToVolume' -oqlFilter "WHERE virtualdevice_id = '$virtualDeviceID'" -ouputFields $outputFields -uri $uri -credentials $credentials} 46 | 'oql' {Get-iTopObject -objectClass 'lnkVirtualDeviceToVolume' -oqlFilter $oqlFilter -ouputFields $outputFields -uri $uri -credentials $credentials} 47 | default {Get-iTopObject -objectClass 'lnkVirtualDeviceToVolume' -uri $uri -credentials $credentials} 48 | } 49 | } 50 | 51 | Function Get-Software { 52 | <# 53 | .Synopsis 54 | Find software 55 | 56 | .Description 57 | Find software 58 | 59 | .Parameter authName 60 | Logon for the iTop web service 61 | 62 | .Parameter authPwd 63 | Password for the iTop web service 64 | 65 | .Parameter uri 66 | uri for the iTop web service 67 | 68 | .Example 69 | Get-Software -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 70 | 71 | .Example 72 | Get-Software -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' -oqlFilter "WHERE name = 'MySQL'" 73 | 74 | #> 75 | Param( 76 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 77 | [Parameter(Mandatory=$True)][string]$uri, 78 | [Parameter(Mandatory=$False)][string]$oqlFilter, 79 | [Parameter(Mandatory=$False)][string]$outputFields='*' 80 | ) 81 | Write-Warning ("Function name {0} is deprecated. Use {1} instead." -f $MyInvocation.MyCommand,"$($MyInvocation.MyCommand.Name -replace '-','-iTop')") 82 | Get-iTopObject -objectClass 'Software' -oqlFilter $oqlFilter -ouputFields $outputFields -uri $uri -credentials $credentials 83 | } 84 | New-Alias -Name Get-iTopSoftware -Value Get-Software -Force 85 | 86 | 87 | Function Get-iTopGlobalIPSetting { 88 | <# 89 | .Synopsis 90 | Find Global IP Settings (IPConfig) 91 | 92 | .Description 93 | Find global IP settings 94 | 95 | .Parameter credentials 96 | PSCredential used for authentication 97 | 98 | .Parameter uri 99 | uri for the iTop web service 100 | 101 | .Example 102 | Get-Software -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 103 | 104 | .Example 105 | Get-Software -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' -oqlFilter "WHERE name = 'MySQL'" 106 | 107 | #> 108 | Param( 109 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 110 | [Parameter(Mandatory=$True)][string]$uri, 111 | [Parameter(Mandatory=$False)][string]$oqlFilter, 112 | [Parameter(Mandatory=$False)][string]$outputFields='*' 113 | ) 114 | Get-iTopObject -objectClass 'IPConfig' -oqlFilter $oqlFilter -ouputFields $outputFields -uri $uri -credentials $credentials 115 | } 116 | 117 | Function Get-iTopDomain { 118 | Param( 119 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 120 | [Parameter(Mandatory=$True)][string]$uri, 121 | [Parameter(Mandatory=$False)][string]$oqlFilter, 122 | [Parameter(Mandatory=$False)][string]$outputFields='*' 123 | ) 124 | Get-iTopObject -objectClass 'Domain' -oqlFilter $oqlFilter -ouputFields $outputFields -uri $uri -credentials $credentials 125 | } 126 | 127 | Function Get-iTopIPUsage { 128 | <# 129 | .Synopsis 130 | Find Global IP Settings (IPConfig) 131 | 132 | .Description 133 | Find global IP settings 134 | 135 | .Parameter credentials 136 | PSCredential used for authentication 137 | 138 | .Parameter uri 139 | uri for the iTop web service 140 | 141 | .Example 142 | Get-Software -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 143 | 144 | .Example 145 | Get-Software -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' -oqlFilter "WHERE name = 'MySQL'" 146 | 147 | #> 148 | Param( 149 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 150 | [Parameter(Mandatory=$True)][string]$uri, 151 | [Parameter(Mandatory=$False)][string]$oqlFilter, 152 | [Parameter(Mandatory=$False)][string]$outputFields='*' 153 | ) 154 | Get-iTopObject -objectClass 'IPUsage' -oqlFilter $oqlFilter -ouputFields $outputFields -uri $uri -credentials $credentials 155 | } 156 | 157 | Function Get-iTopLocation { 158 | <# 159 | .Synopsis 160 | Find software 161 | 162 | .Description 163 | Find software 164 | 165 | .Parameter credentials 166 | PSCredential used for authentication 167 | 168 | .Parameter uri 169 | uri for the iTop web service 170 | 171 | .Example 172 | Get-Software -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 173 | 174 | .Example 175 | Get-Software -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' -oqlFilter "WHERE name = 'MySQL'" 176 | 177 | #> 178 | Param( 179 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 180 | [Parameter(Mandatory=$True)][string]$uri, 181 | [Parameter(Mandatory=$False)][string]$oqlFilter, 182 | [Parameter(Mandatory=$False)][string]$outputFields='*' 183 | ) 184 | Get-iTopObject -objectClass 'Location' -oqlFilter $oqlFilter -ouputFields $outputFields -uri $uri -credentials $credentials 185 | } 186 | 187 | Function Get-SynchroDataSource { 188 | <# 189 | .Synopsis 190 | Find a synchronization data source 191 | 192 | .Description 193 | Find a synchronization data source 194 | 195 | .Parameter authName 196 | Logon for the iTop web service 197 | 198 | .Parameter authPwd 199 | Password for the iTop web service 200 | 201 | .Parameter uri 202 | uri for the iTop web service 203 | 204 | 205 | .Example 206 | Get-SynchroDataSource -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 207 | 208 | .Example 209 | Get-SynchroDataSource -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -eq 'DEV VMware Source'} 210 | 211 | #> 212 | Param( 213 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 214 | [Parameter(Mandatory=$True)][string]$uri, 215 | [Parameter(Mandatory=$False)][string]$oqlFilter, 216 | [Parameter(Mandatory=$False)][string]$outputFields='*' 217 | ) 218 | Write-Warning ("Function name {0} is deprecated. Use {1} instead." -f $MyInvocation.MyCommand,"$($MyInvocation.MyCommand.Name -replace '-','-iTop')") 219 | Get-iTopObject -objectClass 'SynchroDataSource' -oqlFilter $oqlFilter -ouputFields $outputFields -uri $uri -credentials $credentials 220 | } 221 | New-Alias -Name Get-iTopSynchroDataSource -Value Get-SynchroDataSource -Force 222 | 223 | Function Get-FunctionalCI { 224 | <# 225 | .Synopsis 226 | Get a functional CI 227 | 228 | .Description 229 | Get a functional CI 230 | 231 | .Parameter authName 232 | Logon for the iTop web service 233 | 234 | .Parameter authPwd 235 | Password for the iTop web service 236 | 237 | .Parameter uri 238 | uri for the iTop web service 239 | 240 | 241 | .Example 242 | Get-FunctionalCI -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 243 | 244 | .Example 245 | Get-FunctionalCI -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -eq 'DEV VMware Source'} 246 | 247 | #> 248 | Param( 249 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 250 | [Parameter(Mandatory=$True)][string]$uri, 251 | [Parameter(Mandatory=$False)][string]$oqlFilter, 252 | [Parameter(Mandatory=$False)][string]$outputFields='*' 253 | ) 254 | Write-Warning ("Function name {0} is deprecated. Use {1} instead." -f $MyInvocation.MyCommand,"Get-iTopCI") 255 | Get-iTopObject -objectClass 'FunctionalCI' -ouputFields $outputFields -oqlFilter $oqlFilter -uri $uri -credentials $credentials 256 | } 257 | New-Alias -Name Get-iTopCI -Value Get-FunctionalCI -Force 258 | 259 | Function Get-Enclosure { 260 | <# 261 | .Synopsis 262 | Get an enclosure or collection of enclosures 263 | 264 | .Description 265 | Get an enclosure or collection of enclosures 266 | 267 | .Parameter credentials 268 | PSCredential used for authentication 269 | 270 | .Parameter uri 271 | uri for the iTop web service 272 | 273 | .Example 274 | Get-Enclosure -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 275 | 276 | .Example 277 | Get-Enclosure -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.serialnumber -eq 'abc123'} 278 | #> 279 | Param( 280 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 281 | [Parameter(Mandatory=$True)][string]$uri, 282 | [Parameter(Mandatory=$False)][string]$oqlFilter, 283 | [Parameter(Mandatory=$False)][string]$outputFields='*' 284 | ) 285 | 286 | Get-iTopObject -objectClass 'Enclosure' -ouputFields '*' -uri $uri -credentials $credentials -oqlFilter $oqlFilter 287 | } 288 | 289 | Function Get-Rack { 290 | <# 291 | .Synopsis 292 | Get rack or collection of racks 293 | 294 | .Description 295 | Get rack or collection of racks 296 | 297 | .Parameter credentials 298 | PSCredential used for authentication 299 | 300 | .Parameter uri 301 | uri for the iTop web service 302 | 303 | .Example 304 | Get-Rack -credentials (Get-Credential) -uri 'https://webservice.edu' 305 | 306 | .Example 307 | Get-Rack -credentials (Get-Credential) -uri 'https://webservice.edu' -oqlFilter "WHERE name = 'F15'" 308 | 309 | .Example 310 | Get-Rack -credentials (Get-Credential) -uri 'https://webservice.edu' -oqlFilter "WHERE nb_u > 20" 311 | #> 312 | Param( 313 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 314 | [Parameter(Mandatory=$True)][string]$uri, 315 | [Parameter(Mandatory=$False)][string]$oqlFilter, 316 | [Parameter(Mandatory=$False)][string]$outputFields='*' 317 | ) 318 | 319 | Get-iTopObject -objectClass 'Rack' -ouputFields '*' -uri $uri -credentials $credentials -oqlFilter $oqlFilter 320 | } 321 | 322 | Function Get-StorageSystem { 323 | <# 324 | .Synopsis 325 | Get an enclosure or collection of storage systems 326 | 327 | .Description 328 | Get an enclosure or collection of storage systems 329 | 330 | .Parameter credentials 331 | PSCredential used for authentication 332 | 333 | .Parameter uri 334 | uri for the iTop web service 335 | 336 | .Example 337 | Get-StorageSystem -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 338 | 339 | .Example 340 | Get-StorageSystem -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.name -eq 'abc123'} 341 | #> 342 | Param( 343 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 344 | [Parameter(Mandatory=$True)][string]$uri, 345 | [Parameter(Mandatory=$False)][string]$oqlFilter, 346 | [Parameter(Mandatory=$False)][string]$outputFields='*' 347 | ) 348 | 349 | Get-iTopObject -objectClass 'StorageSystem' -oqlFilter $oqlFilter -ouputFields $outputFields -uri $uri -credentials $credentials 350 | } 351 | 352 | Function Get-iTopLogicalInterface { 353 | <# 354 | .Synopsis 355 | Get an logial interface or collection of logical interfaces 356 | 357 | .Description 358 | Get an logial interface or collection of logical interfaces 359 | 360 | .Parameter credentials 361 | PSCredential used for authentication 362 | 363 | .Parameter uri 364 | uri for the iTop web service 365 | 366 | .Example 367 | Get-iTopLogicalInterface -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 368 | 369 | .Example 370 | Get-iTopLogicalInterface -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.macaddress -eq '00:00:00:00:00:00'} 371 | #> 372 | Param( 373 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 374 | [Parameter(Mandatory=$True)][string]$uri, 375 | [Parameter(Mandatory=$False)][string]$oqlFilter, 376 | [Parameter(Mandatory=$False)][string]$outputFields='*' 377 | ) 378 | 379 | Get-iTopObject -objectClass 'LogicalInterface' -oqlFilter $oqlFilter -ouputFields $outputFields -uri $uri -credentials $credentials 380 | } 381 | 382 | Function Get-LogicalVolume { 383 | <# 384 | .Synopsis 385 | Get an enclosure or collection of logical volumes 386 | 387 | .Description 388 | Get an enclosure or collection of logical volumes 389 | 390 | .Parameter credentials 391 | PSCredential used for authentication 392 | 393 | .Parameter uri 394 | uri for the iTop web service 395 | 396 | .Example 397 | Get-LogicalVolume -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 398 | 399 | .Example 400 | Get-LogicalVolume -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.name -eq 'abc123'} 401 | #> 402 | Param( 403 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 404 | [Parameter(Mandatory=$True)][string]$uri, 405 | [Parameter(Mandatory=$False)][string]$oqlFilter, 406 | [Parameter(Mandatory=$False)][string]$outputFields='*' 407 | ) 408 | 409 | Get-iTopObject -objectClass 'LogicalVolume' -ouputFields $outputFields -oqlFilter $oqlFilter -uri $uri -credentials $credentials 410 | } 411 | 412 | Function Get-Brand { 413 | <# 414 | .Synopsis 415 | Get a brand typology or collection of brands 416 | 417 | .Description 418 | Get a brand typology or collection of brands 419 | 420 | .Parameter credentials 421 | PSCredential used for authentication 422 | 423 | .Parameter uri 424 | uri for the iTop web service 425 | 426 | .Example 427 | Get-Brand -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 428 | 429 | .Example 430 | Get-Brand -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -eq 'HP Inc.'} 431 | #> 432 | 433 | Param( 434 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 435 | [Parameter(Mandatory=$True)][string]$uri, 436 | [Parameter(Mandatory=$False)][string]$oqlFilter, 437 | [Parameter(Mandatory=$False)][string]$outputFields='*' 438 | ) 439 | 440 | Get-iTopObject -objectClass 'Brand' -ouputFields $outputFields -oqlFilter $oqlFilter -uri $uri -credentials $credentials 441 | } 442 | 443 | Function Get-ContactType { 444 | <# 445 | .Synopsis 446 | Get a contact type typology or collection of brands 447 | 448 | .Description 449 | Get a contact type typology or collection of brands 450 | 451 | .Parameter authName 452 | Logon for the iTop web service 453 | 454 | .Parameter authPwd 455 | Password for the iTop web service 456 | 457 | .Parameter uri 458 | uri for the iTop web service 459 | 460 | .Example 461 | Get-ContactType -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 462 | 463 | .Example 464 | Get-ContactType -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -eq 'Functional Owner'} 465 | #> 466 | 467 | Param( 468 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 469 | [Parameter(Mandatory=$True)][string]$uri, 470 | [Parameter(Mandatory=$False)][string]$oqlFilter, 471 | [Parameter(Mandatory=$False)][string]$outputFields='*' 472 | ) 473 | 474 | Get-iTopObject -objectClass 'ContactType' -ouputFields $outputFields -oqlFilter $oqlFilter -uri $uri -credentials $credentials 475 | } 476 | New-Alias -Name Get-iTopContactType -Value Get-ContactType -Force 477 | New-Alias -Name Get-iTopRole -Value Get-ContactType -Force 478 | 479 | Function Get-ContractType { 480 | <# 481 | .Synopsis 482 | Get a contract typology or collection of contract types 483 | 484 | .Description 485 | Get a contract typology or collection of contract types 486 | 487 | .Parameter authName 488 | Logon for the iTop web service 489 | 490 | .Parameter authPwd 491 | Password for the iTop web service 492 | 493 | .Parameter uri 494 | uri for the iTop web service 495 | 496 | .Example 497 | Get-ContractType -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 498 | 499 | .Example 500 | Get-ContractType -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -eq 'Blade'} 501 | #> 502 | 503 | Param( 504 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 505 | [Parameter(Mandatory=$True)][string]$uri, 506 | [Parameter(Mandatory=$False)][string]$oqlFilter, 507 | [Parameter(Mandatory=$False)][string]$outputFields='*' 508 | ) 509 | 510 | Get-iTopObject -objectClass 'ContractType' -ouputFields $outputFields -oqlFilter $oqlFilter -uri $uri -credentials $credentials 511 | } 512 | 513 | Function Get-Model { 514 | <# 515 | .Synopsis 516 | Get a model typology or collection of brands 517 | 518 | .Description 519 | Get a model typology or collection of brands 520 | 521 | .Parameter authName 522 | Logon for the iTop web service 523 | 524 | .Parameter authPwd 525 | Password for the iTop web service 526 | 527 | .Parameter uri 528 | uri for the iTop web service 529 | 530 | .Example 531 | Get-Model -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 532 | 533 | .Example 534 | Get-Model -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -eq 'R720'} 535 | #> 536 | Param( 537 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 538 | [Parameter(Mandatory=$True)][string]$uri, 539 | [Parameter(Mandatory=$False)][string]$oqlFilter, 540 | [Parameter(Mandatory=$False)][string]$outputFields='*' 541 | ) 542 | 543 | Get-iTopObject -objectClass 'Model' -ouputFields $outputFields -oqlFilter $oqlFilter -uri $uri -credentials $credentials 544 | } 545 | 546 | Function Get-OSVersion { 547 | <# 548 | .Synopsis 549 | Get an OS Version typology or collection of OS Versions 550 | 551 | .Description 552 | Get an OS Version typology or collection of OS Versions 553 | 554 | .Parameter authName 555 | Logon for the iTop web service 556 | 557 | .Parameter authPwd 558 | Password for the iTop web service 559 | 560 | .Parameter uri 561 | uri for the iTop web service 562 | 563 | .Example 564 | Get-OSVersion -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 565 | 566 | .Example 567 | Get-OSVersion -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -like 'Service Pack*'} 568 | #> 569 | Param( 570 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 571 | [Parameter(Mandatory=$True)][string]$uri 572 | ) 573 | 574 | Get-iTopObject -objectClass 'OSVersion' -ouputFields '*' -uri $uri -credentials $credentials 575 | } 576 | 577 | Function Get-OSFamily { 578 | <# 579 | .Synopsis 580 | Get an OS Family typology or collection of OS Families 581 | 582 | .Description 583 | Get an OS Family typology or collection of OS Families 584 | 585 | .Parameter credentials 586 | PSCredential used for authentication 587 | 588 | .Parameter uri 589 | uri for the iTop web service 590 | 591 | .Example 592 | Get-OSFamily -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 593 | 594 | .Example 595 | Get-OSFamily -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -like 'Microsoft*'} 596 | #> 597 | Param( 598 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 599 | [Parameter(Mandatory=$True)][string]$uri 600 | ) 601 | 602 | Get-iTopObject -objectClass 'OSFamily' -ouputFields '*' -uri $uri -credentials $credentials 603 | } 604 | 605 | Function Get-Server { 606 | <# 607 | .Synopsis 608 | Get a server collection of servers 609 | 610 | .Description 611 | Get a server collection of servers 612 | 613 | .Parameter name 614 | Optional, otherwise returns collection 615 | 616 | .Parameter credentials 617 | PSCredential used for authentication 618 | 619 | .Parameter uri 620 | uri for the iTop web service 621 | 622 | .Example 623 | Get-Model -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 624 | 625 | .Example 626 | Get-Model -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.serialnumber -eq 'H1SMQ3'} 627 | #> 628 | Param( 629 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 630 | [Parameter(Mandatory=$True)][string]$uri, 631 | [Parameter(Mandatory=$False)][string]$oqlFilter, 632 | [Parameter(Mandatory=$False)][string]$outputFields='*' 633 | ) 634 | 635 | Get-iTopObject -objectClass 'Server' -oqlFilter $oqlFilter -ouputFields $outputFields -uri $uri -credentials $credentials 636 | } 637 | 638 | Function Get-VirtualFarm { 639 | <# 640 | .Synopsis 641 | Find a virtual farm / cluster 642 | 643 | .Description 644 | Find a virtual farm / cluster 645 | 646 | .Parameter name 647 | The name of the farm / cluster 648 | 649 | .Parameter authName 650 | Logon for the iTop web service 651 | 652 | .Parameter authPwd 653 | Password for the iTop web service 654 | 655 | .Parameter uri 656 | uri for the iTop web service 657 | 658 | .Example 659 | Get-VirtualFarm -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -eq 'Cluster 1'} 660 | 661 | #> 662 | Param( 663 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 664 | [Parameter(Mandatory=$True)][string]$uri, 665 | [Parameter(Mandatory=$False)][string]$oqlFilter, 666 | [Parameter(Mandatory=$False)][string]$outputFields='*' 667 | ) 668 | 669 | Get-iTopObject -objectClass 'Farm' -ouputFields $outputFields -oqlFilter $oqlFilter -uri $uri -credentials $credentials 670 | } 671 | 672 | Function Get-Hypervisor { 673 | <# 674 | .Synopsis 675 | Get a hypervisor or collection of hypervisors 676 | 677 | .Description 678 | Get a hypervisor or collection of hypervisors 679 | 680 | .Parameter authName 681 | Logon for the iTop web service 682 | 683 | .Parameter authPwd 684 | Password for the iTop web service 685 | 686 | .Parameter uri 687 | uri for the iTop web service 688 | 689 | .Example 690 | Get-Hypervisor -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' -oqlFilter "WHERE name = `'esxServer01`'" -outputFields 'name,id' 691 | 692 | .Example 693 | Get-Hypervisor -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -eq 'Server 1'} 694 | 695 | #> 696 | Param( 697 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 698 | [Parameter(Mandatory=$True)][string]$uri, 699 | [Parameter(Mandatory=$False)][string]$oqlFilter, 700 | [Parameter(Mandatory=$False)][string]$outputFields='*' 701 | ) 702 | 703 | Get-iTopObject -objectClass 'Hypervisor' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 704 | } 705 | 706 | Function Get-DBServer { 707 | <# 708 | .Synopsis 709 | Get a dbserver or collection of dbservers 710 | 711 | .Description 712 | Get a dbserver or collection of dbservers 713 | 714 | .Parameter authName 715 | Logon for the iTop web service 716 | 717 | .Parameter authPwd 718 | Password for the iTop web service 719 | 720 | .Parameter uri 721 | uri for the iTop web service 722 | 723 | .Example 724 | Get-DBServer -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' -oqlFilter "WHERE name = `'mySqlServer01`'" -outputFields 'name,id' 725 | 726 | .Example 727 | Get-DBServer -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -eq 'mySqlServer01'} 728 | 729 | #> 730 | Param( 731 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 732 | [Parameter(Mandatory=$True)][string]$uri, 733 | [Parameter(Mandatory=$False)][string]$oqlFilter, 734 | [Parameter(Mandatory=$False)][string]$outputFields='*' 735 | ) 736 | 737 | Get-iTopObject -objectClass 'DBServer' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 738 | } 739 | 740 | Function Get-Organization { 741 | <# 742 | .Synopsis 743 | Get all organizations 744 | 745 | .Description 746 | Get all organizations 747 | 748 | .Parameter authName 749 | Logon for the iTop web service 750 | 751 | .Parameter authPwd 752 | Password for the iTop web service 753 | 754 | .Parameter uri 755 | uri for the iTop web service 756 | 757 | .Example 758 | Get-Organization -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 759 | 760 | .Example 761 | Get-Organization -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.Name -eq 'UC Berkeley'} 762 | 763 | #> 764 | Param( 765 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 766 | [Parameter(Mandatory=$True)][string]$uri, 767 | [Parameter(Mandatory=$False)][string]$oqlFilter, 768 | [Parameter(Mandatory=$False)][string]$outputFields='*' 769 | ) 770 | 771 | Get-iTopObject -objectClass 'Organization' -ouputFields '*' -uri $uri -credentials $credentials -oqlFilter $oqlFilter 772 | } 773 | 774 | Function Get-Contact { 775 | <# 776 | .Synopsis 777 | Get a contact or collection of contacts 778 | 779 | .Description 780 | Get a contact or collection of contacts including people and teams 781 | 782 | .Parameter authName 783 | Logon for the iTop web service 784 | 785 | .Parameter authPwd 786 | Password for the iTop web service 787 | 788 | .Parameter uri 789 | uri for the iTop web service 790 | 791 | .Example 792 | Get-Person -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 793 | 794 | .Example 795 | Get-Person -employeeNumber 123456 -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 796 | 797 | #> 798 | Param( 799 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 800 | [Parameter(Mandatory=$True)][string]$uri, 801 | [Parameter(Mandatory=$False)][string]$oqlFilter, 802 | [Parameter(Mandatory=$False)][string]$outputFields='*' 803 | ) 804 | 805 | Get-iTopObject -objectClass 'Contact' -uri $uri -credentials $credentials -oqlFilter $oqlFilter -ouputFields $outputFields 806 | } 807 | 808 | Function Get-Team { 809 | <# 810 | .Synopsis 811 | Get a team or collection of teams 812 | 813 | .Description 814 | Get a team or collection of teams 815 | 816 | .Parameter authName 817 | Logon for the iTop web service 818 | 819 | .Parameter authPwd 820 | Password for the iTop web service 821 | 822 | .Parameter uri 823 | uri for the iTop web service 824 | 825 | .Example 826 | Get-Team -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 827 | 828 | #> 829 | Param( 830 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 831 | [Parameter(Mandatory=$True)][string]$uri, 832 | [Parameter(Mandatory=$False)][string]$oqlFilter, 833 | [Parameter(Mandatory=$False)][string]$outputFields='*' 834 | ) 835 | 836 | Get-iTopObject -objectClass 'Team' -uri $uri -credentials $credentials -oqlFilter $oqlFilter -ouputFields $outputFields 837 | } 838 | 839 | Function Get-iTopGroup { 840 | Param( 841 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 842 | [Parameter(Mandatory=$True)][string]$uri, 843 | [Parameter(Mandatory=$False)][string]$oqlFilter, 844 | [Parameter(Mandatory=$False)][string]$outputFields='*' 845 | ) 846 | 847 | Get-iTopObject -objectClass 'Group' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 848 | } 849 | 850 | Function Get-iTopIPv4Address { 851 | <# 852 | .Synopsis 853 | Get a IPv4 address or collection of addresses 854 | 855 | .Description 856 | Get a IPv4 address or collection of addresses 857 | 858 | .Parameter uri 859 | uri for the iTop web service 860 | 861 | .Example 862 | Get-iTopIPv4Address -credentials $cred -uri 'https://webservice.edu' 863 | 864 | .Example 865 | Get-iTopIPv4Address -credentials $cred -uri 'https://webservice.edu' -oqlFilter "WHERE status='Allocated'" 866 | 867 | #> 868 | Param( 869 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 870 | [Parameter(Mandatory=$True)][string]$uri, 871 | [Parameter(Mandatory=$False)][string]$oqlFilter, 872 | [Parameter(Mandatory=$False)][string]$outputFields='*' 873 | ) 874 | 875 | Get-iTopObject -objectClass 'IPv4Address' -uri $uri -credentials $credentials -oqlFilter $oqlFilter -ouputFields $outputFields 876 | } 877 | 878 | Function Get-iTopIPv4Block { 879 | <# 880 | .Synopsis 881 | Get a IPv4 block or collection of blocks 882 | 883 | .Description 884 | Get a IPv4 block or collection of blocks 885 | 886 | .Parameter uri 887 | uri for the iTop web service 888 | 889 | .Example 890 | Get-iTopIPv4Block -credentials $cred -uri 'https://webservice.edu' 891 | 892 | .Example 893 | Get-iTopIPv4Block -credentials $cred -uri 'https://webservice.edu' -oqlFilter "WHERE status='Allocated'" 894 | 895 | #> 896 | Param( 897 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 898 | [Parameter(Mandatory=$True)][string]$uri, 899 | [Parameter(Mandatory=$False)][string]$oqlFilter, 900 | [Parameter(Mandatory=$False)][string]$outputFields='*' 901 | ) 902 | 903 | Get-iTopObject -objectClass 'IPv4Block' -uri $uri -credentials $credentials -oqlFilter $oqlFilter -ouputFields $outputFields 904 | } 905 | 906 | Function Get-iTopIPv4Subnet { 907 | <# 908 | .Synopsis 909 | Get a IPv4 subnets or collection of subnets 910 | 911 | .Description 912 | Get a IPv4 subnets or collection of subnets 913 | 914 | .Parameter uri 915 | uri for the iTop web service 916 | 917 | .Example 918 | Get-iTopIPv4Subnet -credentials $cred -uri 'https://webservice.edu' 919 | 920 | .Example 921 | Get-iTopIPv4Subnet -credentials $cred -uri 'https://webservice.edu' -oqlFilter "WHERE ip='127.0.0.0'" 922 | 923 | #> 924 | Param( 925 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 926 | [Parameter(Mandatory=$True)][string]$uri, 927 | [Parameter(Mandatory=$False)][string]$oqlFilter, 928 | [Parameter(Mandatory=$False)][string]$outputFields='*' 929 | ) 930 | 931 | Get-iTopObject -objectClass 'IPv4Subnet' -uri $uri -credentials $credentials -oqlFilter $oqlFilter -ouputFields $outputFields 932 | } 933 | 934 | Function Get-iTopVlan { 935 | <# 936 | .Synopsis 937 | Get a VLAN or collection of VLANS 938 | 939 | .Description 940 | Get a VLAN subnets or collection of VLANS 941 | 942 | .Parameter uri 943 | uri for the iTop web service 944 | 945 | .Example 946 | Get-iTopVlan -credentials $cred -uri 'https://webservice.edu' 947 | 948 | .Example 949 | Get-iTopVlan -credentials $cred -uri 'https://webservice.edu' -oqlFilter "WHERE vlan_tag='4012'" 950 | 951 | #> 952 | Param( 953 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 954 | [Parameter(Mandatory=$True)][string]$uri, 955 | [Parameter(Mandatory=$False)][string]$oqlFilter, 956 | [Parameter(Mandatory=$False)][string]$outputFields='*' 957 | ) 958 | 959 | Get-iTopObject -objectClass 'VLAN' -uri $uri -credentials $credentials -oqlFilter $oqlFilter -ouputFields $outputFields 960 | } 961 | 962 | Function Get-Person { 963 | <# 964 | .Synopsis 965 | Get a person or collection of people 966 | 967 | .Description 968 | Get a person or collection of people 969 | 970 | .Parameter employeeNumber 971 | Employee number, currently same as UID 972 | 973 | .Parameter credentials 974 | PSCredential used for authentication 975 | 976 | .Parameter uri 977 | uri for the iTop web service 978 | 979 | .Example 980 | Get-Person -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 981 | 982 | .Example 983 | Get-Person -employeeNumber 123456 -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 984 | 985 | #> 986 | Param( 987 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 988 | [Parameter(Mandatory=$True)][string]$uri, 989 | [Parameter(Mandatory=$False)][string]$oqlFilter, 990 | [Parameter(Mandatory=$False)][string]$outputFields='*' 991 | ) 992 | 993 | Get-iTopObject -objectClass 'Person' -uri $uri -credentials $credentials -oqlFilter $oqlFilter -ouputFields $outputFields 994 | } 995 | 996 | Function Get-CustomerContract { 997 | <# 998 | .Synopsis 999 | Get a customer contract or collection of contracts 1000 | 1001 | .Description 1002 | Get a customer contract or collection of contracts 1003 | 1004 | .Parameter authName 1005 | Logon for the iTop web service 1006 | 1007 | .Parameter authPwd 1008 | Password for the iTop web service 1009 | 1010 | .Parameter uri 1011 | uri for the iTop web service 1012 | 1013 | .Example 1014 | Get-CustomerContract -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 1015 | 1016 | .Example 1017 | Get-CustomerContract -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.cost_unit -eq '1-66083-26328-43'} 1018 | 1019 | #> 1020 | Param( 1021 | [Parameter(Mandatory=$False)][string]$oqlFilter, 1022 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1023 | [Parameter(Mandatory=$True)][string]$uri, 1024 | [Parameter(Mandatory=$False)][string]$outputFields='*' 1025 | ) 1026 | 1027 | Get-iTopObject -objectClass 'CustomerContract' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 1028 | } 1029 | 1030 | Function Get-ProviderContract { 1031 | <# 1032 | .Synopsis 1033 | Get a provider contract or collection of contracts 1034 | 1035 | .Description 1036 | Get a provider contract or collection of contracts 1037 | 1038 | .Parameter authName 1039 | Logon for the iTop web service 1040 | 1041 | .Parameter authPwd 1042 | Password for the iTop web service 1043 | 1044 | .Parameter uri 1045 | uri for the iTop web service 1046 | 1047 | .Example 1048 | Get-ProviderContract -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 1049 | 1050 | .Example 1051 | Get-ProviderContract -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' | Where {$_.cost_unit -eq '1-66083-26328-43'} 1052 | 1053 | #> 1054 | Param( 1055 | [Parameter(Mandatory=$False)][string]$oqlFilter, 1056 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1057 | [Parameter(Mandatory=$True)][string]$uri, 1058 | [Parameter(Mandatory=$False)][string]$outputFields='*' 1059 | ) 1060 | 1061 | Get-iTopObject -objectClass 'ProviderContract' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 1062 | } 1063 | 1064 | Function Get-LinkServiceToSLA { 1065 | Param( 1066 | [Parameter(Mandatory=$True)][object]$service, 1067 | [Parameter(Mandatory=$True)][object]$sla 1068 | ) 1069 | 1070 | $thisArray = @() 1071 | $ciHash = @{} 1072 | $ciHash.add("service_id",("SELECT Service WHERE id =`"$($service.key)`"")) 1073 | $ciHash.add("sla_id",("SELECT SLA WHERE id =`"$($sla.key)`"")) 1074 | 1075 | $thisArray += $ciHash 1076 | ,$thisArray 1077 | } 1078 | 1079 | Function New-CustomerContract { 1080 | Param( 1081 | [Parameter(Mandatory=$True)][string]$name, 1082 | [Parameter(Mandatory=$True)][string]$org_name, 1083 | [Parameter(Mandatory=$False)][string]$description, 1084 | [Parameter(Mandatory=$False)][string]$start_date, 1085 | [Parameter(Mandatory=$False)][string]$end_date, 1086 | [Parameter(Mandatory=$False)][string]$cost, 1087 | [Parameter(Mandatory=$False)][string]$cost_currency='dollars', 1088 | [Parameter(Mandatory=$False)][string]$contracttype_name, # use SELECT ContractType to get relation 1089 | [Parameter(Mandatory=$False)]$contacts, # collection of people CIs 1090 | [Parameter(Mandatory=$False)][string]$billing_frequency, 1091 | [Parameter(Mandatory=$False)][string]$cost_unit, 1092 | [Parameter(Mandatory=$True)][string]$provider_name, #use SELECT Organization of of provider 1093 | [Parameter(Mandatory=$True)][string]$status='production', 1094 | [Parameter(Mandatory=$False)]$functionalcis, # collection of CI objects 1095 | [Parameter(Mandatory=$False)]$linkServiceToSLA, # array of service to sla hash, get-linkservicetosla 1096 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1097 | [Parameter(Mandatory=$True)][string]$uri 1098 | ) 1099 | 1100 | # build our linked objects, iTop only want certain lookup fields per object, so we'll feed those in 1101 | $contacts_list = @() 1102 | foreach($ci in $contacts) { 1103 | $ciHash = @{} 1104 | $ciHash.add("contact_id",("SELECT Contact WHERE id =`"$($ci.key)`"")) 1105 | $contacts_list += $ciHash 1106 | } 1107 | 1108 | $functionalcis_list = @() 1109 | foreach($ci in $functionalcis) { 1110 | $ciHash = @{} 1111 | $ciHash.add("functionalci_id",("SELECT FunctionalCI WHERE id =`"$($ci.key)`"")) 1112 | $functionalcis_list += $ciHash 1113 | } 1114 | 1115 | 1116 | $fields = New-Object PSObject -Property @{ 1117 | name = $name 1118 | org_id = "SELECT Organization WHERE name = `"$org_name`"" 1119 | description = $description 1120 | start_date = $start_date 1121 | end_date = $end_date 1122 | cost = $cost 1123 | cost_currency = $cost_currency 1124 | contracttype_id = "SELECT ContractType WHERE name = `"$contracttype_name`"" 1125 | contacts_list = $contacts_list 1126 | billing_frequency = $billing_frequency 1127 | cost_unit = $cost_unit 1128 | provider_id = "SELECT Organization WHERE name = `"$provider_name`"" 1129 | status = $status 1130 | services_list = $linkServiceToSLA 1131 | functionalcis_list = $functionalcis_list 1132 | } 1133 | 1134 | $operation = New-Object PSObject -Property @{ 1135 | operation = 'core/create' 1136 | class = 'CustomerContract' 1137 | comment = 'Synchronization from load scripts' 1138 | output_fields = '*' 1139 | fields = $fields 1140 | } 1141 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1142 | } 1143 | 1144 | Function New-Organization { 1145 | Param( 1146 | [Parameter(Mandatory=$True)][string]$name, 1147 | [Parameter(Mandatory=$True)][string]$code, 1148 | [Parameter(Mandatory=$True)][string]$parent_name, 1149 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1150 | [Parameter(Mandatory=$True)][string]$uri 1151 | ) 1152 | $fields = New-Object PSObject -Property @{ 1153 | parent_id = "SELECT Organization WHERE name = `"$parent_name`"" 1154 | name = $name 1155 | code = $code 1156 | } 1157 | 1158 | $operation = New-Object PSObject -Property @{ 1159 | operation = 'core/create' 1160 | class = 'Organization' 1161 | comment = 'Synchronization from load scripts' 1162 | output_fields = '*' 1163 | fields = $fields 1164 | } 1165 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1166 | } 1167 | 1168 | Function New-Brand { 1169 | Param( 1170 | [Parameter(Mandatory=$True)][string]$name, 1171 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1172 | [Parameter(Mandatory=$True)][string]$uri 1173 | ) 1174 | $fields = New-Object PSObject -Property @{ 1175 | name = $name 1176 | } 1177 | 1178 | $operation = New-Object PSObject -Property @{ 1179 | operation = 'core/create' 1180 | class = 'Brand' 1181 | comment = 'Synchronization from load scripts' 1182 | output_fields = '*' 1183 | fields = $fields 1184 | } 1185 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1186 | } 1187 | 1188 | Function New-ContactType { 1189 | Param( 1190 | [Parameter(Mandatory=$True)][string]$name, 1191 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1192 | [Parameter(Mandatory=$True)][string]$uri 1193 | ) 1194 | $fields = New-Object PSObject -Property @{ 1195 | name = $name 1196 | } 1197 | 1198 | $operation = New-Object PSObject -Property @{ 1199 | operation = 'core/create' 1200 | class = 'ContactType' 1201 | comment = 'Synchronization from load scripts' 1202 | output_fields = '*' 1203 | fields = $fields 1204 | } 1205 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1206 | } 1207 | 1208 | Function New-Model { 1209 | Param( 1210 | [Parameter(Mandatory=$True)][string]$name, 1211 | [Parameter(Mandatory=$True)][string]$type, 1212 | [Parameter(Mandatory=$True)][string]$brand_id, 1213 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1214 | [Parameter(Mandatory=$True)][string]$uri 1215 | ) 1216 | $fields = New-Object PSObject -Property @{ 1217 | name = $name 1218 | type = $type 1219 | brand_id = $brand_id 1220 | } 1221 | 1222 | $operation = New-Object PSObject -Property @{ 1223 | operation = 'core/create' 1224 | class = 'Model' 1225 | comment = 'Synchronization from load scripts' 1226 | output_fields = '*' 1227 | fields = $fields 1228 | } 1229 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1230 | } 1231 | 1232 | Function New-OSFamily { 1233 | Param( 1234 | [Parameter(Mandatory=$True)][string]$name, 1235 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1236 | [Parameter(Mandatory=$True)][string]$uri 1237 | ) 1238 | $fields = New-Object PSObject -Property @{ 1239 | name = $name 1240 | } 1241 | 1242 | $operation = New-Object PSObject -Property @{ 1243 | operation = 'core/create' 1244 | class = 'OSFamily' 1245 | comment = 'Created via API call' 1246 | output_fields = '*' 1247 | fields = $fields 1248 | } 1249 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1250 | } 1251 | 1252 | Function New-OSVersion { 1253 | Param( 1254 | [Parameter(Mandatory=$True)][string]$name, 1255 | [Parameter(Mandatory=$True)][string]$osfamily_name, 1256 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1257 | [Parameter(Mandatory=$True)][string]$uri 1258 | ) 1259 | $fields = New-Object PSObject -Property @{ 1260 | name = $name 1261 | osfamily_id = "SELECT OSFamily WHERE name = `"$osfamily_name`"" 1262 | } 1263 | 1264 | $operation = New-Object PSObject -Property @{ 1265 | operation = 'core/create' 1266 | class = 'OSVersion' 1267 | comment = 'Created via API call' 1268 | output_fields = '*' 1269 | fields = $fields 1270 | } 1271 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1272 | } 1273 | 1274 | Function New-VirtualFarm { 1275 | Param( 1276 | [Parameter(Mandatory=$True)][string]$uuid, 1277 | [Parameter(Mandatory=$True)][string]$name, 1278 | [Parameter(Mandatory=$True)][string]$org_name, 1279 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1280 | [Parameter(Mandatory=$True)][string]$uri 1281 | ) 1282 | $fields = New-Object PSObject -Property @{ 1283 | org_id = "SELECT Organization WHERE name = `"$org_name`"" 1284 | name = $name 1285 | uuid = $uuid 1286 | } 1287 | 1288 | $operation = New-Object PSObject -Property @{ 1289 | operation = 'core/create' 1290 | class = 'Farm' 1291 | comment = 'Synchronization from vCenter' 1292 | output_fields = '*' 1293 | fields = $fields 1294 | } 1295 | 1296 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1297 | } 1298 | 1299 | Function New-Hypervisor { 1300 | Param( 1301 | [Parameter(Mandatory=$True)][string]$name, 1302 | [Parameter(Mandatory=$True)][string]$org_name, 1303 | [Parameter(Mandatory=$False)][string]$farm_name, 1304 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1305 | [Parameter(Mandatory=$True)][string]$uri 1306 | ) 1307 | 1308 | $fields = New-Object PSObject -Property @{ 1309 | org_id = "SELECT Organization WHERE name = `"$org_name`"" 1310 | name = $name 1311 | } 1312 | 1313 | # add optional parameters 1314 | if($farm_name -ne $null -and $farm_name -ne 'host' -and $farm_name -ne '') { 1315 | $fields | Add-Member -NotePropertyName farm_id -NotePropertyValue "SELECT Farm WHERE name = `"$farm_name`"" 1316 | } 1317 | 1318 | $operation = New-Object PSObject -Property @{ 1319 | operation = 'core/create' 1320 | class = 'Hypervisor' 1321 | comment = 'Synchronization from vCenter' 1322 | output_fields = '*' 1323 | fields = $fields 1324 | } 1325 | 1326 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1327 | } 1328 | 1329 | Function New-Team { 1330 | Param( 1331 | [Parameter(Mandatory=$True)][string]$name, 1332 | [Parameter(Mandatory=$False)][string]$email = $null, 1333 | [Parameter(Mandatory=$False)][string]$phone = $null, 1334 | [Parameter(Mandatory=$False)][string]$orgName, 1335 | [Parameter(Mandatory=$False)][string]$orgID, 1336 | [Parameter(Mandatory=$False)][string]$function, 1337 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1338 | [Parameter(Mandatory=$True)][string]$uri 1339 | ) 1340 | 1341 | if($PSBoundParameters.ContainsKey('orgName')) { 1342 | $fields = New-Object PSObject -Property @{ 1343 | org_id = "SELECT Organization WHERE name = `"$orgName`"" 1344 | name = $name 1345 | } 1346 | } else { 1347 | $fields = New-Object PSObject -Property @{ 1348 | org_id = "SELECT Organization WHERE id = `"$orgID`"" 1349 | name = $name 1350 | } 1351 | } 1352 | 1353 | 1354 | # add optional parameters 1355 | if(![String]::IsNullOrEmpty($phone)) { 1356 | $fields | Add-Member -NotePropertyName 'phone' -NotePropertyValue $phone 1357 | } 1358 | if(![String]::IsNullOrEmpty($email)) { 1359 | $fields | Add-Member -NotePropertyName 'email' -NotePropertyValue $email 1360 | } 1361 | if(![String]::IsNullOrEmpty($function)) { 1362 | $fields | Add-Member -NotePropertyName 'function' -NotePropertyValue $function 1363 | } 1364 | 1365 | New-iTopObject -objectClass 'Team' -fields $fields -credentials $credentials -uri $uri 1366 | } 1367 | 1368 | Function New-Person { 1369 | Param( 1370 | [Parameter(Mandatory=$True)][string]$firstName, 1371 | [Parameter(Mandatory=$True)][string]$lastName, 1372 | [Parameter(Mandatory=$True)][string]$email, 1373 | [Parameter(Mandatory=$False)][string]$phone = $null, 1374 | [Parameter(Mandatory=$True)][string]$orgName, 1375 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1376 | [Parameter(Mandatory=$True)][string]$uri 1377 | ) 1378 | 1379 | $fields = New-Object PSObject -Property @{ 1380 | org_id = "SELECT Organization WHERE name = `"$orgName`"" 1381 | name = $lastName 1382 | first_name = $firstName 1383 | email = $email 1384 | } 1385 | 1386 | # add optional parameters 1387 | if(![String]::IsNullOrEmpty($phone)) { 1388 | $fields | Add-Member -NotePropertyName 'phone' -NotePropertyValue $phone 1389 | } 1390 | 1391 | $operation = New-Object PSObject -Property @{ 1392 | operation = 'core/create' 1393 | class = 'Person' 1394 | comment = 'Created using API' 1395 | output_fields = '*' 1396 | fields = $fields 1397 | } 1398 | 1399 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1400 | } 1401 | 1402 | Function New-VirtualMachine { 1403 | <# 1404 | .Synopsis 1405 | Creates a VirtualMachine object in iTop 1406 | 1407 | .Description 1408 | Creates a VirtualMachine object in iTop 1409 | 1410 | .Parameter uui 1411 | The unique ID of the VM 1412 | 1413 | .Parameter name 1414 | The name of the VM 1415 | 1416 | .Parameter numCPU 1417 | Number of virtual CPUs 1418 | 1419 | .Parameter ramGB 1420 | Amount of memory in GB 1421 | 1422 | .Parameter hostName 1423 | The hypervisor name, must already exist in iTop 1424 | 1425 | .Parameter org 1426 | The organization name, must already exist in iTop 1427 | 1428 | .Parameter authName 1429 | Logon for the iTop web service 1430 | 1431 | .Parameter authPwd 1432 | Password for the iTop web service 1433 | 1434 | .Parameter uri 1435 | uri for the iTop web service 1436 | 1437 | .Example 1438 | Create-VirtualMachine -uuid '0001-0002-0003-00004' -name 'MyVM' -orgName 'Department A' -authName 'user' -authPwd 'password' -uri 'https://webservice.edu' 1439 | 1440 | #> 1441 | 1442 | Param( 1443 | [Parameter(Mandatory=$True)][string]$uuid, 1444 | [Parameter(Mandatory=$True)][string]$name, 1445 | [Parameter(Mandatory=$False)][string]$numCPU, 1446 | [Parameter(Mandatory=$False)][string]$ramGB, 1447 | [Parameter(Mandatory=$True)][string]$hostName, 1448 | [Parameter(Mandatory=$false)][string]$orgName, 1449 | [Parameter(Mandatory=$false)][string]$orgID, 1450 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1451 | [Parameter(Mandatory=$True)][string]$uri 1452 | ) 1453 | 1454 | if($PSBoundParameters.ContainsKey('orgName')) { 1455 | $fields = New-Object PSObject -Property @{ 1456 | org_id = "SELECT Organization WHERE name = `"$orgName`"" 1457 | virtualhost_id = "SELECT VirtualHost WHERE name = `"$hostName`"" 1458 | name = $name 1459 | uuid = $uuid 1460 | } 1461 | } else { 1462 | $fields = New-Object PSObject -Property @{ 1463 | org_id = "SELECT Organization WHERE id = `"$orgID`"" 1464 | virtualhost_id = "SELECT VirtualHost WHERE name = `"$hostName`"" 1465 | name = $name 1466 | uuid = $uuid 1467 | } 1468 | } 1469 | 1470 | 1471 | # add optional parameters 1472 | if($numCPU -ne $null) { 1473 | $fields | Add-Member -NotePropertyName 'cpu' -NotePropertyValue $numCPU 1474 | } 1475 | if($ramGB -ne $null) { 1476 | $fields | Add-Member -NotePropertyName 'ram' -NotePropertyValue $ramGB 1477 | } 1478 | 1479 | $operation = New-Object PSObject -Property @{ 1480 | operation = 'core/create' 1481 | class = 'VirtualMachine' 1482 | comment = 'Synchronization from vCenter' 1483 | output_fields = '*' 1484 | fields = $fields 1485 | } 1486 | 1487 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1488 | } 1489 | 1490 | Function Get-VirtualMachine { 1491 | Param( 1492 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1493 | [Parameter(Mandatory=$True)][string]$uri, 1494 | [Parameter(Mandatory=$False)][string]$oqlFilter, 1495 | [Parameter(Mandatory=$False)][string]$outputFields='*' 1496 | ) 1497 | 1498 | Get-iTopObject -objectClass 'VirtualMachine' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 1499 | } 1500 | 1501 | Function Get-ApplicationSolution { 1502 | Param( 1503 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1504 | [Parameter(Mandatory=$True)][string]$uri, 1505 | [Parameter(Mandatory=$False)][string]$oqlFilter, 1506 | [Parameter(Mandatory=$False)][string]$outputFields='*' 1507 | ) 1508 | 1509 | Get-iTopObject -objectClass 'ApplicationSolution' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 1510 | } 1511 | 1512 | Function Get-SynchroReplica { 1513 | Param( 1514 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1515 | [Parameter(Mandatory=$True)][string]$uri, 1516 | [Parameter(Mandatory=$False)][string]$oqlFilter, 1517 | [Parameter(Mandatory=$False)][string]$outputFields='*' 1518 | ) 1519 | 1520 | Get-iTopObject -objectClass 'SynchroReplica' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 1521 | } 1522 | 1523 | Function Remove-CustomerContract { 1524 | Param( 1525 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1526 | [Parameter(Mandatory=$True)][string]$uri, 1527 | [Parameter(Mandatory=$True)]$customerContract 1528 | ) 1529 | 1530 | Remove-iTopObject -credentials $credentials -uri $uri -object $customerContract 1531 | } 1532 | 1533 | Function Remove-iTopObject { 1534 | Param( 1535 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1536 | [Parameter(Mandatory=$True)][string]$uri, 1537 | [Parameter(Mandatory=$True)]$object 1538 | ) 1539 | 1540 | $operation = New-Object PSObject -Property @{ 1541 | operation = 'core/delete' 1542 | class = $object.class 1543 | key = $object.key 1544 | } 1545 | 1546 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1547 | } 1548 | 1549 | Function Set-Team { 1550 | 1551 | <# 1552 | .Synopsis 1553 | Updates / sets values on a Team CI 1554 | 1555 | .Description 1556 | Updates / sets values on a Team CI 1557 | 1558 | .Parameter team 1559 | The Team CI 1560 | 1561 | .Parameter PersonRoles 1562 | Hashtable of Person CI (key) : Role CI (val) 1563 | 1564 | .Parameter CIs 1565 | String or array of CIs owned by the team 1566 | 1567 | .Parameter orgName 1568 | The organization name, must already exist in iTop 1569 | 1570 | .Parameter authName 1571 | Logon for the iTop web service 1572 | 1573 | .Parameter authPwd 1574 | Password for the iTop web service 1575 | 1576 | .Parameter uri 1577 | uri for the iTop web service 1578 | 1579 | .Example 1580 | $personCI = Get-Person -Name "Walter Becker" 1581 | $roleCI = Get-Role -Name "Bass Player" 1582 | Get-Team -Name "Steely Dan" | Set-Team -PersonRoles @{$personCI = $roleCI} 1583 | 1584 | #> 1585 | Param( 1586 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1587 | [Parameter(Mandatory=$True)][string]$uri, 1588 | [Parameter(Mandatory=$True)]$team, 1589 | [Parameter(Mandatory=$False)][hashtable]$PersonRoles=$null, 1590 | [Parameter(Mandatory=$False)]$CIs=$null, 1591 | [Parameter(Mandatory=$False)]$orgId=$null 1592 | ) 1593 | 1594 | #This is the way we might want to start moving all Set functions to 1595 | 1596 | # Create a hash table to store all of the fields 1597 | $propertyBag = @{} 1598 | 1599 | if($PersonRoles -ne $nul) { 1600 | $personsList = @() 1601 | foreach($person in $PersonRoles.Keys) { 1602 | $role = $PersonRoles.$person 1603 | $personHash = @{} 1604 | 1605 | if($person.key -ne $null) { 1606 | $personHash.Add('person_id',("SELECT Contact WHERE id = `"$($person.key)`"")) 1607 | } 1608 | elseif($person.contact_id -ne $null) { 1609 | $personHash.add("person_id",("SELECT Contact WHERE id = `"$($person.contact_id)`"")) 1610 | } 1611 | elseif($person.person_id -ne $null) { 1612 | $personHash.add("person_id",("SELECT Contact WHERE id = `"$($person.person_id)`"")) 1613 | } 1614 | 1615 | if($role -ne $null) { 1616 | $personHash.Add('role_id',("SELECT ContactType WHERE name = `"$($role.name)`"")) 1617 | } 1618 | 1619 | # Add to the array only if not already there 1620 | $alreadyAdded = $false 1621 | foreach($existingPersonHash in $personsList) { 1622 | if(($existingPersonHash.'person_id' -eq $personHash.'person_id') -and ($existingPersonHash.'role_id' -eq $personHash.'role_id')) { 1623 | $alreadyAdded = $true 1624 | break 1625 | } 1626 | } 1627 | if(!$alreadyAdded) { 1628 | $personsList += $personHash 1629 | } 1630 | } 1631 | $propertyBag.Add('persons_list',$personsList) 1632 | } 1633 | if($CIs -ne $null) { 1634 | $propertyBag.Add('cis_list',$CIs) 1635 | } 1636 | 1637 | Set-iTopObject -credentials $credentials -uri $uri -iTopObject $team -propertyBag $propertyBag 1638 | 1639 | } 1640 | 1641 | Function Set-iTopGlobalIPSetting { 1642 | Param( 1643 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1644 | [Parameter(Mandatory=$True)][string]$uri, 1645 | [Parameter(Mandatory=$True)]$globalIPSetting, 1646 | [Parameter(Mandatory=$False)][int]$ipv4BlockMinSize, 1647 | [Parameter(Mandatory=$False)][ValidateSet('dtc_no','dtc_yes')][string]$delegateToChildrenOnly='dtc_no', 1648 | [Parameter(Mandatory=$False)][ValidateSet('reserve_no','reserve_yes')][string]$reserveSubnetIPs='dtc_yes', 1649 | [Parameter(Mandatory=$False)][ValidateSet('ipdup_no','ipdup_yes')][string]$allowDuplicateShortName='ipdup_yes' 1650 | ) 1651 | 1652 | $propertyBag = @{} 1653 | 1654 | if($PSBoundParameters.ContainsKey('ipv4BlockMinSize')) { 1655 | $propertyBag.Add('ipv4_block_min_size',$ipv4BlockMinSize) 1656 | } 1657 | if($PSBoundParameters.ContainsKey('delegateToChildrenOnly')) { 1658 | $propertyBag.Add('delegate_to_children_only',$delegateToChildrenOnly) 1659 | } 1660 | if($PSBoundParameters.ContainsKey('reserveSubnetIPs')) { 1661 | $propertyBag.Add('reserve_subnet_IPs',$reserveSubnetIPs) 1662 | } 1663 | if($PSBoundParameters.ContainsKey('allowDuplicateShortName')) { 1664 | $propertyBag.Add('ip_allow_duplicate_name',$allowDuplicateShortName) 1665 | } 1666 | 1667 | Set-iTopObject -credentials $credentials -uri $uri -iTopObject $globalIPSetting -propertyBag $propertyBag 1668 | } 1669 | 1670 | 1671 | Function Set-iTopObject { 1672 | Param( 1673 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1674 | [Parameter(Mandatory=$True)][string]$uri, 1675 | [Parameter(Mandatory=$True)]$iTopObject, 1676 | [Parameter(Mandatory=$False)]$propertyBag=@{} 1677 | ) 1678 | 1679 | if($iTopObject.key -eq $null) { 1680 | Throw "Please pass a full iTop object to Set- commandlets. Missing the key property." 1681 | } 1682 | 1683 | $fields = New-Object PSObject -Property @{} 1684 | 1685 | # Property bag can contain a Hashtable to property name/values 1686 | if($propertyBag.count -gt 0) { 1687 | foreach($key in $propertyBag.keys) { 1688 | $fields | Add-Member -MemberType NoteProperty -Name $key -Value $propertyBag[$key] 1689 | } 1690 | } 1691 | 1692 | $class = $null 1693 | if(![string]::IsNullOrEmpty($iTopObject.finalclass)) { 1694 | $class = $iTopObject.finalclass 1695 | } 1696 | elseif(![string]::IsNullOrEmpty($iTopObject.class)) { 1697 | $class = $iTopObject.class 1698 | } 1699 | 1700 | $operation = New-Object PSObject -Property @{ 1701 | operation = 'core/update' 1702 | class = $class 1703 | key = $iTopObject.key 1704 | comment = 'update from API' 1705 | output_fields = '*' 1706 | fields = $fields 1707 | } 1708 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1709 | 1710 | } 1711 | 1712 | Function Set-FunctionalCI { 1713 | Param( 1714 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1715 | [Parameter(Mandatory=$True)][string]$uri, 1716 | [Parameter(Mandatory=$True)]$ci, 1717 | [Parameter(Mandatory=$False)]$contacts, 1718 | [Parameter(Mandatory=$False)]$applicationSolutions, 1719 | [Parameter(Mandatory=$False)]$orgId=$null, 1720 | [Parameter(Mandatory=$False)]$propertyBag=@{} 1721 | ) 1722 | 1723 | 1724 | # build our linked objects, iTop only want certain lookup fields per object, so we'll feed those in 1725 | $contacts_list = @() 1726 | foreach($contact in $contacts) { 1727 | $contactHash = @{} 1728 | if($contact.key -ne $null) { 1729 | $contactHash.add("contact_id",("SELECT Contact WHERE id = `"$($contact.key)`"")) 1730 | } 1731 | elseif($contact.contact_id -ne $null) { 1732 | $contactHash.add("contact_id",("SELECT Contact WHERE id = `"$($contact.contact_id)`"")) 1733 | } 1734 | $contacts_list += $contactHash 1735 | } 1736 | 1737 | $applicationsolution_list = @() 1738 | foreach($applicationsolution in $applicationSolutions) { 1739 | $appSolutionHash = @{} 1740 | $appSolutionHash.add("applicationsolution_id",("SELECT ApplicationSolution WHERE id = `"$($applicationsolution.key)`"")) 1741 | $applicationsolution_list += $appSolutionHash 1742 | } 1743 | 1744 | $fields = New-Object PSObject -Property @{} 1745 | 1746 | if($contacts_list.Count -gt 0) { 1747 | $fields | Add-Member -MemberType NoteProperty -Name 'contacts_list' -Value $contacts_list 1748 | } 1749 | if($applicationsolution_list.Count -gt 0) { 1750 | $fields | Add-Member -MemberType NoteProperty -Name 'applicationsolution_list' -Value $applicationsolution_list 1751 | } 1752 | if(![string]::IsNullOrEmpty($orgId)) { 1753 | $fields | Add-Member -MemberType NoteProperty -Name 'org_id' -Value "SELECT Organization WHERE id = `"$orgId`"" 1754 | } 1755 | # Property bag can contain a Hashtable to property name/values 1756 | if($propertyBag.count -gt 0) { 1757 | foreach($key in $propertyBag.keys) { 1758 | $fields | Add-Member -MemberType NoteProperty -Name $key -Value $propertyBag[$key] 1759 | } 1760 | } 1761 | 1762 | $operation = New-Object PSObject -Property @{ 1763 | operation = 'core/update' 1764 | class = 'FunctionalCI' 1765 | key = $ci.key 1766 | comment = 'update from API' 1767 | output_fields = '*' 1768 | fields = $fields 1769 | } 1770 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 1771 | } 1772 | 1773 | Function Set-CustomerContract { 1774 | Param( 1775 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1776 | [Parameter(Mandatory=$True)][string]$uri, 1777 | [Parameter(Mandatory=$True)]$customerContract, 1778 | [Parameter(Mandatory=$False)]$contacts, 1779 | [Parameter(Mandatory=$False)]$functionalCIs, 1780 | [Parameter(Mandatory=$False)]$orgId=$null, 1781 | [Parameter(Mandatory=$False)]$cost_unit=$null, 1782 | [Parameter(Mandatory=$False)]$start_date=$null, 1783 | [Parameter(Mandatory=$False)]$end_date=$null, 1784 | [Parameter(Mandatory=$False)]$services_list # array of service to sla hash, get-linkservicetosla 1785 | ) 1786 | 1787 | 1788 | # build our linked objects, iTop only wants certain lookup fields per object, so we'll feed those in 1789 | $contacts_list = @() 1790 | foreach($contact in $contacts) { 1791 | $contactHash = @{} 1792 | if($contact.key -ne $null) { 1793 | $contactHash.add("contact_id",("SELECT Contact WHERE id = `"$($contact.key)`"")) 1794 | } 1795 | elseif($contact.contact_id -ne $null) { 1796 | $contactHash.add("contact_id",("SELECT Contact WHERE id = `"$($contact.contact_id)`"")) 1797 | } 1798 | elseif($contact.person_id -ne $null) { 1799 | $contactHash.add("contact_id",("SELECT Contact WHERE id = `"$($contact.person_id)`"")) 1800 | } 1801 | $contacts_list += $contactHash 1802 | } 1803 | 1804 | $functionalcis_list = @() 1805 | foreach($functionalCI in $functionalCIs | ? {$_ -ne $null}) { 1806 | $functionalciHash = @{} 1807 | $functionalciHash.add("functionalci_id",("SELECT FunctionalCI WHERE id = `"$($functionalCI.key)`"")) 1808 | $functionalcis_list += $functionalciHash 1809 | } 1810 | 1811 | $propertyBag = @{} 1812 | 1813 | if($contacts_list.Count -gt 0) { 1814 | $propertyBag.Add('contacts_list',$contacts_list) 1815 | } 1816 | if($functionalcis_list.Count -gt 0) { 1817 | $propertyBag.Add('functionalcis_list',$functionalcis_list) 1818 | } 1819 | if($PSBoundParameters.ContainsKey('org_id')) { 1820 | $propertyBag.Add('org_id',"SELECT Organization WHERE id = `"$orgId`"") 1821 | } 1822 | if($PSBoundParameters.ContainsKey('cost_unit')) { 1823 | $propertyBag.Add('cost_unit',$cost_unit) 1824 | } 1825 | if($PSBoundParameters.ContainsKey('start_date')) { 1826 | $propertyBag.Add('start_date',$start_date) 1827 | } 1828 | if($PSBoundParameters.ContainsKey('end_date')) { 1829 | $propertyBag.Add('end_date',$end_date) 1830 | } 1831 | if($PSBoundParameters.ContainsKey('services_list')) { 1832 | $propertyBag.Add('services_list',$services_list) 1833 | } 1834 | 1835 | Set-iTopObject -credentials $credentials -uri $uri -iTopObject $customerContract -propertyBag $propertyBag 1836 | } 1837 | 1838 | Function Set-VirtualMachine { 1839 | Param( 1840 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1841 | [Parameter(Mandatory=$True)][string]$uri, 1842 | [Parameter(Mandatory=$True)]$virtualMachine, 1843 | [Parameter(Mandatory=$False)]$contacts, 1844 | [Parameter(Mandatory=$False)]$org_id=$null, 1845 | [Parameter(Mandatory=$False)]$dataclassification=$null 1846 | ) 1847 | 1848 | # build our linked objects, iTop only wants certain lookup fields per object, so we'll feed those in 1849 | $contacts_list = @() 1850 | foreach($contact in $contacts) { 1851 | $contactHash = @{} 1852 | if($contact.key -ne $null) { 1853 | $contactHash.add("contact_id",("SELECT Contact WHERE id = `"$($contact.key)`"")) 1854 | } 1855 | elseif($contact.contact_id -ne $null) { 1856 | $contactHash.add("contact_id",("SELECT Contact WHERE id = `"$($contact.contact_id)`"")) 1857 | } 1858 | elseif($contact.person_id -ne $null) { 1859 | $contactHash.add("contact_id",("SELECT Contact WHERE id = `"$($contact.person_id)`"")) 1860 | } 1861 | $contacts_list += $contactHash 1862 | } 1863 | 1864 | $propertyBag = @{} 1865 | 1866 | if($contacts_list.Count -gt 0) { 1867 | $propertyBag.Add('contacts_list',$contacts_list) 1868 | } 1869 | if($PSBoundParameters.ContainsKey('org_id')) { 1870 | $propertyBag.Add('org_id',"SELECT Organization WHERE id = `"$org_id`"") 1871 | } 1872 | if($PSBoundParameters.ContainsKey('dataclassification')) { 1873 | $propertyBag.Add('dataclassification',$dataclassification) 1874 | } 1875 | 1876 | Set-iTopObject -credentials $credentials -uri $uri -iTopObject $virtualMachine -propertyBag $propertyBag 1877 | } 1878 | 1879 | Function New-iTopDomain { 1880 | Param( 1881 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1882 | [Parameter(Mandatory=$True)][string]$uri, 1883 | [Parameter(Mandatory=$True)][string]$name, 1884 | [Parameter(Mandatory=$True)]$orgId 1885 | ) 1886 | 1887 | $fields = New-Object PSObject -Property @{ 1888 | name = $name;org_id = "SELECT Organization WHERE id = `"$orgId`"" 1889 | } 1890 | New-iTopObject -objectClass 'Domain' -fields $fields -credentials $credentials -uri $uri 1891 | } 1892 | 1893 | Function New-Software { 1894 | Param( 1895 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1896 | [Parameter(Mandatory=$True)][string]$uri, 1897 | [Parameter(Mandatory=$True)][string]$name, 1898 | [Parameter(Mandatory=$True)][string]$vendor, 1899 | [Parameter(Mandatory=$True)][string]$version, 1900 | [Parameter(Mandatory=$True)][string]$type 1901 | ) 1902 | 1903 | $propertyBag = @{} 1904 | if($PSBoundParameters.ContainsKey('vendor')) { 1905 | $propertyBag.Add('vendor',$vendor) 1906 | } 1907 | if($PSBoundParameters.ContainsKey('version')) { 1908 | $propertyBag.Add('version',$version) 1909 | } 1910 | if($PSBoundParameters.ContainsKey('type')) { 1911 | $propertyBag.Add('type',$type) 1912 | } 1913 | 1914 | # Before creating check to see if it already exists using all 'keys' 1915 | $oqlFilter = "WHERE name = '$name'" 1916 | $propertyBag.Keys | % {$oqlFilter += " AND $_ = '$($propertyBag.$_)'"} 1917 | 1918 | $thisSoftware = Get-Software -credentials $credentials -uri $uri -oqlFilter $oqlFilter 1919 | if(!$thisSoftware) { 1920 | $fields = New-Object PSObject -Property @{ 1921 | name = $name 1922 | } 1923 | 1924 | $propertyBag.Keys | % {$fields | Add-Member -MemberType NoteProperty -Name $_ -Value $propertyBag.$_} 1925 | 1926 | New-iTopObject -objectClass "Software" -fields $fields -credentials $credentials -uri $uri 1927 | } 1928 | else { 1929 | $thisSoftware 1930 | } 1931 | } 1932 | 1933 | Function Get-Service { 1934 | Param( 1935 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1936 | [Parameter(Mandatory=$True)][string]$uri, 1937 | [Parameter(Mandatory=$False)][string]$oqlFilter, 1938 | [Parameter(Mandatory=$False)][string]$outputFields='*' 1939 | ) 1940 | 1941 | Get-iTopObject -objectClass 'Service' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 1942 | 1943 | } 1944 | 1945 | Function Get-SLA { 1946 | Param( 1947 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1948 | [Parameter(Mandatory=$True)][string]$uri, 1949 | [Parameter(Mandatory=$False)][string]$oqlFilter, 1950 | [Parameter(Mandatory=$False)][string]$outputFields='*' 1951 | ) 1952 | 1953 | Get-iTopObject -objectClass 'SLA' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 1954 | } 1955 | 1956 | Function Get-LDAPUser { 1957 | Param( 1958 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1959 | [Parameter(Mandatory=$True)][string]$uri, 1960 | [Parameter(Mandatory=$False)][string]$oqlFilter, 1961 | [Parameter(Mandatory=$False)][string]$outputFields='*' 1962 | ) 1963 | 1964 | Get-iTopObject -objectClass 'UserLDAP' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 1965 | } 1966 | 1967 | Function New-LDAPUser { 1968 | Param( 1969 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 1970 | [Parameter(Mandatory=$True)][string]$uri, 1971 | [Parameter(Mandatory=$True)]$contact, 1972 | [Parameter(Mandatory=$True)][string]$login, 1973 | [Parameter(Mandatory=$True)][array]$profiles, 1974 | [Parameter(Mandatory=$False)][array]$allowedOrgs 1975 | ) 1976 | # build our linked objects, iTop only want certain lookup fields per object, so we'll feed those in 1977 | $profile_list = @() 1978 | foreach($p in $profiles) { 1979 | $pHash = @{} 1980 | $phash.add("profileid",("SELECT URP_Profiles WHERE id =`"$($p.key)`"")) 1981 | $profile_list += $pHash 1982 | } 1983 | 1984 | $allowed_org_list = @() 1985 | foreach($o in $allowedOrgs) { 1986 | $oHash = @{} 1987 | $oHash.add("allowed_org_id",("SELECT Organization WHERE id =`"$($o.key)`"")) 1988 | $allowed_org_list += $oHash 1989 | } 1990 | 1991 | $fields = New-Object PSObject -Property @{ 1992 | contactid = $contact.key 1993 | profile_list = $profile_list 1994 | allowed_org_list = $allowed_org_list 1995 | login = $login 1996 | } 1997 | 1998 | $operation = New-Object PSObject -Property @{ 1999 | operation = 'core/create' 2000 | class = 'UserLDAP' 2001 | comment = 'Create from API call' 2002 | output_fields = '*' 2003 | fields = $fields 2004 | } 2005 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 2006 | } 2007 | 2008 | Function Get-Profile { 2009 | Param( 2010 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 2011 | [Parameter(Mandatory=$True)][string]$uri, 2012 | [Parameter(Mandatory=$False)][string]$oqlFilter, 2013 | [Parameter(Mandatory=$False)][string]$outputFields='*' 2014 | ) 2015 | Get-iTopObject -objectClass 'URP_Profiles' -ouputFields $outputFields -uri $uri -credentials $credentials -oqlFilter $oqlFilter 2016 | } 2017 | 2018 | Function New-VirtualMachineReplica { 2019 | Param( 2020 | [Parameter(Mandatory=$True)][string]$uuid, 2021 | [Parameter(Mandatory=$True)][string]$name, 2022 | [Parameter(Mandatory=$False)][string]$cpu, 2023 | [Parameter(Mandatory=$False)][string]$ram, 2024 | [Parameter(Mandatory=$True)][string]$virtualhost_id, 2025 | [Parameter(Mandatory=$True)][string]$orgKey, 2026 | [Parameter(Mandatory=$True)][object]$datasourceObject, 2027 | [Parameter(Mandatory=$True)][string]$ITOP_DB_Server, 2028 | [Parameter(Mandatory=$True)][string]$ITOP_DB_authName, 2029 | [Parameter(Mandatory=$True)][string]$ITOP_DB_authPwd, 2030 | [Parameter(Mandatory=$True)][string]$ITOP_DB_Name 2031 | ) 2032 | 2033 | $synchroTableName = $datasourceObject.database_table_name 2034 | 2035 | # Update VM synchro data 2036 | $updateStatement = "INSERT INTO $synchroTableName (primary_key,uuid,virtualhost_id,name,org_id,business_criticity,status,cpu,ram) 2037 | VALUES (`'$uuid`',`'$uuid`',`'$virtualhost_id`',`'$name`',$orgKey,`'$businessCriticity`',`'$status`',`'$cpu`',`'$ram`') 2038 | ON DUPLICATE KEY UPDATE 2039 | name=VALUES(name), 2040 | org_id=VALUES(org_id), 2041 | virtualhost_id=VALUES(virtualhost_id), 2042 | cpu=VALUES(cpu), 2043 | ram=VALUES(ram)" 2044 | 2045 | $res = Invoke-NonQuery -serverName $ITOP_DB_Server -userName $ITOP_DB_authName -password $ITOP_DB_authPwd -dbName $ITOP_DB_Name -query $updateStatement 2046 | $res 2047 | } 2048 | 2049 | Function Get-iTopObject { 2050 | <# 2051 | .Synopsis 2052 | Retrieves an iTop object. 2053 | 2054 | .Description 2055 | Private helper function. All Get-* commandlets go here. This is a generic handler for getting iTop objects using the REST service and an OQL query. 2056 | 2057 | .Parameter oqlFilter 2058 | Optional WHERE clause of an OQL query to filter results. 2059 | 2060 | .Parameter objectClass 2061 | The type iTop object to return. 2062 | 2063 | .Parameter ouputFields 2064 | Fields to return. By default returns all fields. 2065 | 2066 | .Parameter authName 2067 | Logon for the iTop web service 2068 | 2069 | .Parameter authPwd 2070 | Password for the iTop web service 2071 | 2072 | .Parameter uri 2073 | uri for the iTop web service 2074 | #> 2075 | 2076 | Param( 2077 | [Parameter(Mandatory=$False)][string]$oqlFilter, 2078 | [Parameter(Mandatory=$True)][string]$objectClass, 2079 | [Parameter(Mandatory=$False)][string]$ouputFields='*', 2080 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 2081 | [Parameter(Mandatory=$True)][string]$uri 2082 | ) 2083 | 2084 | $query = "SELECT $objectClass" 2085 | 2086 | # Calculate our OQL query 2087 | if(![string]::IsNullOrEmpty($oqlFilter)) { 2088 | $query = $query + " $oqlFilter" 2089 | } 2090 | 2091 | # Create a hash/psobject of our request 2092 | $operation = New-Object PSObject -Property @{ 2093 | operation = 'core/get' 2094 | class = $objectClass 2095 | key = $query 2096 | output_fields = $ouputFields 2097 | } 2098 | 2099 | # Format the request and send it to iTop 2100 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 2101 | } 2102 | 2103 | Function New-iTopObject { 2104 | Param( 2105 | [Parameter(Mandatory=$True)][string]$objectClass, 2106 | [Parameter(Mandatory=$True)]$fields, 2107 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 2108 | [Parameter(Mandatory=$True)][string]$uri 2109 | ) 2110 | 2111 | # Take in an array of PSObject, the class name, and anything mandatory 2112 | # Format the request and send it to iTop 2113 | $operation = New-Object PSObject -Property @{ 2114 | operation = 'core/create' 2115 | class = $objectClass 2116 | comment = 'Created using API' 2117 | output_fields = '*' 2118 | fields = $fields 2119 | } 2120 | 2121 | GenerateAndSendRequest -credentials $credentials -uri $uri -requestHash $operation 2122 | } 2123 | 2124 | Function Invoke-SynchroImport { 2125 | <# 2126 | .Synopsis 2127 | Invoke the synchro import over the webservice. 2128 | 2129 | .Description 2130 | Invoke the synchro import over the webservice. Expects the URI as something like https://myserver.com/itop/synchro/synchro_import.php 2131 | 2132 | .Parameter dataSource 2133 | The datasource object to run the synchro 2134 | 2135 | .Parameter authName 2136 | Logon for the iTop web service 2137 | 2138 | .Parameter authPwd 2139 | Password for the iTop web service 2140 | 2141 | .Parameter uri 2142 | uri for the iTop web service 2143 | 2144 | .Parameter csvData 2145 | the csv data array 2146 | 2147 | #> 2148 | 2149 | Param( 2150 | [Parameter(Mandatory=$True)]$dataSource, 2151 | [Parameter(Mandatory=$True)]$credentials, 2152 | [Parameter(Mandatory=$True)]$uri, 2153 | [Parameter(Mandatory=$True)]$csvData 2154 | 2155 | ) 2156 | 2157 | # build our paramter hash 2158 | $requestBody = @{ 2159 | data_source_id=$dataSource.key 2160 | auth_user=$credentials.UserName 2161 | auth_pwd=$credentials.GetNetworkCredential().Password 2162 | csvdata = $csvData 2163 | } 2164 | 2165 | # send the web request and get the response 2166 | $res = Invoke-WebRequest -Method Post -Uri $uri -Body $requestBody -TimeoutSec 960 -UseBasicParsing 2167 | if($res.StatusCode -eq 200) { 2168 | $res 2169 | } 2170 | else { 2171 | Throw "Synchro_import returned an error when running $res" 2172 | } 2173 | } 2174 | 2175 | Function Invoke-BulkExport { 2176 | <# 2177 | .Synopsis 2178 | Invoke the bulk export API. 2179 | 2180 | .Description 2181 | See https://www.itophub.io/wiki/page?id=2_2_0%3Aadvancedtopics%3Aexportdata 2182 | 2183 | .Parameter expression 2184 | OQL query 2185 | 2186 | .Parameter authName 2187 | Logon for the iTop web service 2188 | 2189 | .Parameter authPwd 2190 | Password for the iTop web service 2191 | 2192 | .Parameter uri 2193 | uri for the iTop web service 2194 | 2195 | .Parameter fields 2196 | comma separated list of fields to return 2197 | 2198 | #> 2199 | Param( 2200 | [Parameter(Mandatory=$True)][string]$expression, 2201 | [Parameter(Mandatory=$True)][pscredential]$credential, 2202 | [Parameter(Mandatory=$True)][string]$uri, 2203 | [Parameter(Mandatory=$True)][ValidateSet("html","csv","xml","xlsx")]$format = "csv", 2204 | [Parameter(Mandatory=$True)][string]$fields 2205 | ) 2206 | 2207 | $encExpression = [System.Web.HttpUtility]::UrlEncode($expression) 2208 | 2209 | $fullUri = "{0}?expression={1}&format={2}&login_mode={3}&fields={4}" -f $uri,$encExpression,$format,"basic",$fields 2210 | 2211 | # send the web request and get the response 2212 | $res = Invoke-WebRequest -Method Get -Uri $fullUri -TimeoutSec 960 -UseBasicParsing -Credential $credential 2213 | if($res.StatusCode -eq 200) { 2214 | $res.Content 2215 | } 2216 | else { 2217 | Throw "Bulk export returned an error when running $res" 2218 | } 2219 | } 2220 | 2221 | 2222 | Function Invoke-SynchroExec { 2223 | <# 2224 | .Synopsis 2225 | Invoke the synchro exec over the webservice. 2226 | 2227 | .Description 2228 | Invoke the synchro exec over the webservice. Expects the URI as something like https://myserver.com/itop/synchro/synchro_exec.php 2229 | 2230 | .Parameter dataSource 2231 | The datasource object to run the synchro 2232 | 2233 | .Parameter authName 2234 | Logon for the iTop web service 2235 | 2236 | .Parameter authPwd 2237 | Password for the iTop web service 2238 | 2239 | .Parameter uri 2240 | uri for the iTop web service 2241 | #> 2242 | 2243 | Param( 2244 | [Parameter(Mandatory=$True)]$dataSource, 2245 | [Parameter(Mandatory=$TRUE)]$credentials, 2246 | [Parameter(Mandatory=$TRUE)]$uri 2247 | ) 2248 | 2249 | # build our paramter hash 2250 | $requestBody = @{ 2251 | data_sources=$dataSource.key 2252 | auth_user=$credentials.UserName 2253 | auth_pwd=$credentials.GetNetworkCredential().Password 2254 | } 2255 | 2256 | # send the web request and get the response 2257 | $res = Invoke-WebRequest -Method Post -Uri $uri -Body $requestBody -TimeoutSec 960 -UseBasicParsing 2258 | if($res.StatusCode -eq 200) { 2259 | $res 2260 | } 2261 | else { 2262 | Throw "Synchro_exec returned an error when running $res" 2263 | } 2264 | } 2265 | 2266 | Function Invoke-SyncScript { 2267 | Param( 2268 | [Parameter(Mandatory=$TRUE)]$datasourceObject, 2269 | [Parameter(Mandatory=$TRUE)]$ITOP_SSH_Username, 2270 | [Parameter(Mandatory=$TRUE)]$ITOP_SSH_Key, 2271 | [Parameter(Mandatory=$TRUE)]$ITOP_SSH_Passphrase, 2272 | [Parameter(Mandatory=$TRUE)]$ITOP_authName, 2273 | [Parameter(Mandatory=$TRUE)]$ITOP_authPwd, 2274 | [Parameter(Mandatory=$TRUE)]$ITOP_sync_exe_path, 2275 | [Parameter(Mandatory=$TRUE)]$ITOP_server_name 2276 | ) 2277 | 2278 | $session = New-SshSession -ComputerName $ITOP_server_name -Username $ITOP_SSH_Username -KeyFile $ITOP_SSH_Key -Passphrase $ITOP_SSH_Passphrase 2279 | $command = 'php -q ' + $ITOP_sync_exe_path + ' --auth_user=' + $ITOP_authName + ' --auth_pwd=' + $ITOP_authPwd + ' --data_sources=' + $datasourceObject.key 2280 | $sshRes = Invoke-SshCommand -ComputerName $ITOP_server_name -Command $command 2281 | $sshRes 2282 | } 2283 | 2284 | Function GenerateAndSendRequest { 2285 | <# 2286 | .Synopsis 2287 | Format an iTop request and handle the result. 2288 | 2289 | .Description 2290 | Private helper function. Any interaction with iTop Get-/Set-/New- should go through this. 2291 | 2292 | .Parameter requestHash 2293 | A hashtable of the request to be converted to JSON 2294 | 2295 | .Parameter authName 2296 | Logon for the iTop web service 2297 | 2298 | .Parameter authPwd 2299 | Password for the iTop web service 2300 | 2301 | .Parameter uri 2302 | uri for the iTop web service 2303 | #> 2304 | Param( 2305 | [Parameter(Mandatory=$True)][PSCredential]$credentials, 2306 | [Parameter(Mandatory=$True)][string]$uri, 2307 | [Parameter(Mandatory=$True)]$requestHash 2308 | ) 2309 | 2310 | $requestBody = @{ 2311 | version="1.1" 2312 | auth_user=$credentials.UserName 2313 | auth_pwd=$credentials.GetNetworkCredential().Password 2314 | json_data=ConvertTo-Json($requestHash) -Depth 10 2315 | } 2316 | 2317 | # Make our request to the web service 2318 | $resp = Invoke-WebRequest -Method Post -Uri $uri -Body $requestBody -TimeoutSec 480 -DisableKeepAlive:$True -UseBasicParsing 2319 | $result = $null 2320 | 2321 | if($IsWindows) { 2322 | # Let's use the .Net JavaScript serializer, the PowerShell implementation is limited in length 2323 | [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") 2324 | $javaScriptSerializer = New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer 2325 | $javaScriptSerializer.MaxJsonLength = [int]::MaxValue 2326 | $javaScriptSerializer.RecursionLimit = 99 2327 | 2328 | # Deserialize the request into a PowerShell object 2329 | $result = $javaScriptSerializer.DeserializeObject($resp.Content) 2330 | } else { 2331 | $result = $resp.Content | ConvertFrom-Json 2332 | } 2333 | 2334 | # Is there an unexpected exception? 2335 | if($result.code -ne 0) { 2336 | throw "Result code = $($result.code), $($result.message)" 2337 | } 2338 | 2339 | # If we have empty objects that simply means the search worked but came up empty for some reason 2340 | if($result.objects.count -eq 0) { 2341 | # Return null 2342 | $null 2343 | } 2344 | 2345 | # Looks like we have at least one object to return, let's create a PSObject because it's easier to enum 2346 | # We can also add the key and class type of the iTop object 2347 | foreach ($key in $result.objects.Keys) { 2348 | $thisObject = New-Object -Type PSObject -Property $result.objects.$key.fields 2349 | if($null -ne $result.objects.$key.key) { 2350 | # using the newer API, let's add the key 2351 | $thisObject | Add-Member Noteproperty -Name "key" -Value $result.objects.$key.key 2352 | } 2353 | if($null -ne $result.objects.$key.class) { 2354 | # using the newer API, let's add the class 2355 | $thisObject | Add-Member Noteproperty -Name "class" -Value $result.objects.$key.class 2356 | } 2357 | # put the object on the pipline 2358 | $thisObject 2359 | } 2360 | } 2361 | 2362 | Export-ModuleMember -Function * -Alias * --------------------------------------------------------------------------------