TechDirect.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 |
<#
.NOTES -------------------------------------------------------------------------------- Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.171 Generated on: 2/21/2020 11:02 AM Generated by: dz053479 Organization: CernerWorks -------------------------------------------------------------------------------- .DESCRIPTION Script generated by PowerShell Studio 2020 #> <# =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2019 v5.6.167 Created on: 9/3/2019 8:37 AM Created by: D.Z. Organization: N/A Filename: TechDirect.psm1 ------------------------------------------------------------------------- Module Name: TechDirect =========================================================================== #> function Connect-TechDirect { <# .SYNOPSIS This function will acquire an Access Token from TechDirect .DESCRIPTION This function will acquire an Access Token from TechDirect for use with TechDirect Warranty and Self-Dispatch APIs .PARAMETER Warranty Used to incidate a request for a Warranty API Token .PARAMETER Dispatch Used to incidate a request for a Self-Dispatch API Token .PARAMETER Sandbox Used to request a token using the sandbox environment. Sandbox is not available for the Warranty API. .PARAMETER ClientID Client ID provided by TechDirect for your API access. .PARAMETER ClientSecret Client Secret provided by TechDirect for your API access. .EXAMPLE PS C:\> Connect-TechDirect -ClientID 'ABCDEFGHIJKL' -ClientSecret 'ZYXWVUTSRQPONML' .EXAMPLE PS C:\> Connect-TechDirect -ClientID 'ABCDEFGHIJKL' -ClientSecret 'ZYXWVUTSRQPONML' -Sandbox .NOTES Additional information about the function. #> [CmdletBinding(DefaultParameterSetName = 'Warranty', ConfirmImpact = 'None', PositionalBinding = $true, SupportsPaging = $false, SupportsShouldProcess = $false)] param ( [Parameter(ParameterSetName = 'Warranty', Position = 1)] [switch]$Warranty, [Parameter(ParameterSetName = 'Dispatch', Position = 1)] [switch]$Dispatch, [Parameter(ParameterSetName = 'Dispatch', Position = 2)] [switch]$Sandbox, [Parameter(Mandatory = $true)] [string]$ClientID, [Parameter(Mandatory = $true)] [string]$ClientSecret ) $Bytes = [System.Text.Encoding]::UTF8.GetBytes($($ClientID + ":" + $ClientSecret)) $Base64Key = [System.Convert]::ToBase64String($Bytes) $Header = @{ Authorization = "Basic $Base64Key" } $Body = "grant_type=client_credentials" if ($sandbox) { $Endpoint = "apigtwb2cnp.us.dell.com" } else { $Endpoint = "apigtwb2c.us.dell.com" } Try { $Token = Invoke-RestMethod "https://$Endpoint/auth/oauth/v2/token" -Method Post -Body $Body -ContentType "application/x-www-form-urlencoded" -Headers $Header if ($sandbox) { $Token | Add-Member -MemberType NoteProperty -Name sandbox -Value $True } else { $Token | Add-Member -MemberType NoteProperty -Name sandbox -Value $False } $Token | Add-Member -MemberType NoteProperty "expire_time" -Value (Get-Date).AddSeconds($Token.expires_in) -Force if (!(Test-Path "$env:LOCALAPPDATA\TechDirect\")) { New-Item -Path "$env:LOCALAPPDATA\TechDirect\" -ItemType directory -Force | Out-Null } if ($Warranty) { $Token | Add-Member -MemberType NoteProperty "expire_time" -Value (Get-Date).AddSeconds($Token.expires_in) -Force $Token | ConvertTo-Json | Out-File $env:LOCALAPPDATA\TechDirect\Token-W.json -Force } elseif ($Dispatch) { $Token | Add-Member -MemberType NoteProperty "expire_time" -Value (Get-Date).AddSeconds($Token.expires_in) -Force $Token | ConvertTo-Json | Out-File $env:LOCALAPPDATA\TechDirect\Token-D.json -Force } Write-Output "`r`nSuccessfully acquired TechDirect token.`r`n" return $Token } catch { $result = $_.Exception.Response.GetResponseStream() $reader = New-Object System.IO.StreamReader($result) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() $response = $reader.ReadToEnd(); $statuscode = $_.Exception.Response.StatusCode.value__ $ErrCategory = [system.management.automation.errorcategory]::InvalidOperation $ErrorRecord = New-Object System.Management.Automation.ErrorRecord($(($Response | ConvertFrom-Json).error_description), "$statuscode", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } function Get-TDAccessToken { [CmdletBinding()] param ( [switch]$Warranty, [switch]$Dispatch ) if ($Warranty) { if (Test-Path "$env:LOCALAPPDATA\TechDirect\Token-W.json") { try { $TokenInfo = Get-Content $env:LOCALAPPDATA\TechDirect\Token-W.json | ConvertFrom-Json } catch { $ErrCategory = [system.management.automation.errorcategory]::SecurityError $ErrorRecord = New-Object System.Management.Automation.ErrorRecord("Token does not exist or is corrupted, use 'Connect-TechDirect' to acquire a token", "", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } else { $ErrCategory = [system.management.automation.errorcategory]::SecurityError $ErrorRecord = New-Object System.Management.Automation.ErrorRecord("Token does not exist or is corrupted, use 'Connect-TechDirect' to acquire a token", "", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } elseif ($Dispatch) { if (Test-Path "$env:LOCALAPPDATA\TechDirect\Token-D.json") { try { $TokenInfo = Get-Content $env:LOCALAPPDATA\TechDirect\Token-D.json | ConvertFrom-Json } catch { $ErrCategory = [system.management.automation.errorcategory]::SecurityError $ErrorRecord = New-Object System.Management.Automation.ErrorRecord("Token does not exist or is corrupted, use 'Connect-TechDirect' to acquire a token", "", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } else { $ErrCategory = [system.management.automation.errorcategory]::SecurityError $ErrorRecord = New-Object System.Management.Automation.ErrorRecord("Token does not exist or is corrupted, use 'Connect-TechDirect' to acquire a token", "", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } else { return } $UTCOffset = [System.TimeZoneInfo]::Local.GetUtcOffset((get-date)).totalminutes $TokenInfo.expire_time = $TokenInfo.expire_time.AddMinutes($UTCOffset) $TokenInfo.expires_in = [math]::Round((New-timespan (get-date) $TokenInfo.expire_time).TotalSeconds, 0) if ($TokenInfo.expire_time -le (get-date)) { $ErrCategory = [system.management.automation.errorcategory]::AuthenticationError $ErrorRecord = New-Object System.Management.Automation.ErrorRecord("Token is expired, use 'Connect-TechDirect' to acquire a new token", "", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) return } return $TokenInfo } function Format-DispatchPart { param ([string]$PartNumber, [string]$PPID, [int]$Quantity) $part = "<api:PartInfo>`r`n" $Part += "`t<api:PartNumber>$PartNumber</api:PartNumber>`r`n" if ($PPID) { $Part += "`t<api:PPID>$PPID</api:PPID>`r`n" } else { $Part += "`t<api:PPID/>`r`n" } $Part += "`t<api:Quanitity>$Quantity</api:Quanitity>`r`n" $Part += "</api:PartInfo>" return $part } function Format-DispatchAttachment { param ( [string]$Description, [string]$FilePath ) Begin { Add-Type -AssemblyName "System.Web" } Process { $FileName = (Get-Item $FilePath).Name if ($Description -eq "") { $Description = $FileName } $MIMEType = [System.Web.MimeMapping]::GetMimeMapping("$FilePath") $FileData = Convert-FileToBase64 $FilePath $XML = @" <api:AttachmentInfo> <api:Description>$Description</api:Description> <api:FileName>$FileName</api:FileName> <api:MIMEType>$MIMEType</api:MIMEType> <api:Data>$FileData</api:Data> </api:AttachmentInfo> "@ return $XML } } function Get-TechnicianStatus { <# .SYNOPSIS Check Technician Status. .DESCRIPTION Provides account level details. Account should be active and not expired for API transactions to complete. .PARAMETER Credentials Credential Object containing the Username/Password of the Technician .EXAMPLE $Credentials = (Get-Credential) PS C:\> Get-TechnicianStatus -Credentials $Credentials #> [CmdletBinding(ConfirmImpact = 'None', SupportsPaging = $false, SupportsShouldProcess = $false)] param ( [Parameter(Mandatory = $false)] [pscredential]$Credentials = (Get-Credential -message "Enter TechDirect Credentials:") ) $Username = ($PSboundparameters.Credentials).getnetworkcredential().Username $Password = ($PSboundparameters.Credentials).getnetworkcredential().Password $XML = @" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.dell.com"> <soapenv:Header/> <soapenv:Body> <api:CheckUser> <api:CheckUserRequest> <api:Login>$Username</api:Login> <api:Password>$Password</api:Password> </api:CheckUserRequest> </api:CheckUser> </soapenv:Body> </soapenv:Envelope> "@ $DellToken = Get-TDAccessToken -Dispatch if ($DellToken.sandbox) { $endpoint = "https://apigtwb2cnp.us.dell.com/Sandbox/support/dispatch/v3/service" } else { $endpoint = "https://apigtwb2c.us.dell.com/PROD/support/dispatch/v3/service" } $Headers = @{ Authorization = "Bearer $($DellToken.access_token)" SOAPAction = "http://api.dell.com/IDispatchService/CheckUser" } try { $Response = Invoke-RestMethod $endpoint -Method Post -Body ([xml]$XML) -Headers $Headers -ContentType "text/xml" $Result = $Response.Envelope.Body.CheckUserResponse.CheckUserResult.LoginResult ####### We have to parse the XML response manually, since Powershell doesn't want to convert it to JSON natively $JSON = [pscustomobject]@{ FullName = $Result.FullName Role = $Result.Role PasswordExpirationDate = [datetime]$Result.PasswordExpirationDate Inactive = $Result.Inactive Locked = $Result.Locked } return $JSON } catch { $result = $_.Exception.Response.GetResponseStream() $reader = New-Object System.IO.StreamReader($result) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() $response = $reader.ReadToEnd(); $ResponseMessage = ([xml]$Response).Envelope.Body.Fault $statuscode = $_.Exception.Response.StatusCode.value__ $ErrCategory = [system.management.automation.errorcategory]::InvalidOperation $ErrorRecord = New-Object System.Management.Automation.ErrorRecord($($ResponseMessage.faultstring), "$statuscode", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } function Get-TechnicianInfo { <# .SYNOPSIS Get detailed information about Technician .DESCRIPTION A detailed description of the Get-TechnicianInfo function. .PARAMETER Credentials Credential Object containing the Username/Password of the Technician .EXAMPLE PS C:\> Get-TechnicianInfo .NOTES Additional information about the function. #> [CmdletBinding()] param ( [Parameter(Mandatory = $false)] [pscredential]$Credentials = (Get-Credential -message "Enter TechDirect Credentials:") ) $Username = ($PSboundparameters.Credentials).getnetworkcredential().Username $Password = ($PSboundparameters.Credentials).getnetworkcredential().Password $XML = @" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.dell.com"> <soapenv:Header/> <soapenv:Body> <api:CheckLogin> <api:CheckLoginRequest> <api:Login>$Username</api:Login> <api:Password>$Password</api:Password> </api:CheckLoginRequest> </api:CheckLogin> </soapenv:Body> </soapenv:Envelope> "@ $DellToken = Get-TDAccessToken -Dispatch if ($DellToken.sandbox) { $endpoint = "https://apigtwb2cnp.us.dell.com/Sandbox/support/dispatch/v3/service" } else { $endpoint = "https://apigtwb2c.us.dell.com/PROD/support/dispatch/v3/service" } $Headers = @{ Authorization = "Bearer $($DellToken.access_token)" SOAPAction = "http://api.dell.com/IDispatchService/CheckLogin" } Try { $Response = Invoke-RestMethod $endpoint -Method Post -Body ([xml]$XML) -Headers $Headers -ContentType "text/xml" $Result = $Response.Envelope.Body.CheckLoginResponse.CheckLoginResult.LoginResult ####### We have to parse the XML response manually, since Powershell doesn't want to convert it to JSON natively $Relationships = $Result.Relationships.RelationshipInfo $Groups = @() foreach ($Relationship in $Relationships) { $Group = [pscustomobject]@{ BranchName = $Relationship.BranchName CustomerName = $Relationship.CustomerName Track = $Relationship.Track } $Groups += $Group } $Certs = $Result.Certificates.CertificateInfo $Certifications = @() foreach ($cert in $Certs) { $Certificate = [pscustomobject]@{ Certificate = $cert.certificate ExpirationDate = $cert.ExpirationDate } $Certifications += $Certificate } $JSON = [pscustomobject]@{ FullName = $Result.FullName Role = $Result.Role PasswordExpirationDate = [datetime]$Result.PasswordExpirationDate HomeBranch = $Result.HomeBranch Relationships = $Groups Certificates = $Certifications DSP = $Result.DSP } return $JSON } catch { $result = $_.Exception.Response.GetResponseStream() $reader = New-Object System.IO.StreamReader($result) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() $response = $reader.ReadToEnd(); $ResponseMessage = ([xml]$Response).Envelope.Body.Fault $statuscode = $_.Exception.Response.StatusCode.value__ $ErrCategory = [system.management.automation.errorcategory]::InvalidOperation $ErrorRecord = New-Object System.Management.Automation.ErrorRecord($($ResponseMessage.faultstring), "$statuscode", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } function Invoke-DispatchRequest { <# .SYNOPSIS Initiate dispatch with TechDirect .DESCRIPTION Function to initiate a request for parts. This request is asynchronous, a Work Order is returned on successfully transacting with the Dispatch system. The WO number can then be queried to track the status of the Work Order. 'Get-DispatchStatus' will be the primary method to track status of an WO. 'Get-Dispatches' function can be used for querying more than one WO. For successful processing of a WO always submit - i. Contact information ii. Shipping information iii. Parts information iv. Service tag of the failed system v. Troubleshooting notes and evidence of failure. .PARAMETER Credentials Credential Object containing the Username/Password of the Technician .PARAMETER TechEmail Contains the email of the technician responsible for the dispatch. In the case of a logistics user this may be different from the login email .PARAMETER Branch Contains the branch associated with the dispatch. Note that the technician must be authorized to dispatch parts from this branch .PARAMETER Customer Contains the customer associated with the dispatch. The customer must have a valid relationship with the branch in order to successfully dispatch .PARAMETER Track Contains the track associated with the Branch to Customer relationship (this can be obtained using 'Get-TechnicianInfo') .PARAMETER ServiceTag The service tag associated with the dispatch .PARAMETER PrimaryContactName The primary contact associated with the dispatch. .PARAMETER PrimaryContactPhone The primary contact phone number for the dispatch .PARAMETER PrimaryContactEmail The primary contact email associated with the dispatch. .PARAMETER AlternateContactName Additional/Alternate contact name .PARAMETER AlternateContactPhone Additional/Alternate contact number .PARAMETER ReferencePONumber Optional purchase order or internal reference number .PARAMETER AddressBookName The name of a personal or company address book entry. If this is specified the detail address parameters are not allowed. .PARAMETER CountryISOCode ISO country code for the ship-to address .PARAMETER City The ship-to city .PARAMETER State The ship-to state .PARAMETER ZipCode The ship-to zip or postal code .PARAMETER AddressLine1 The first ship-to address line .PARAMETER AddressLine2 The second ship-to address line .PARAMETER AddressLine3 The third ship-to address line .PARAMETER TimeZone A description of the TimeZone parameter. .PARAMETER RequestCompleteCare A true/false parameter indicating if accidental damage applies to this dispatch .PARAMETER RequestReturnToDepot A true/false parameter indicating if return to depot applies to this dispatch .PARAMETER RequestOnSiteTechnician A true/false parameter indicating if an onsite technician is requested .PARAMETER TroubleshootingNote Contains troubleshooting notes, limited to 1000 characters .PARAMETER Parts An array of part information associated with the dispatch. This is limited to a maximum of 4 parts per dispatch Use 'Get-PartsByServiceTag' to query replaceable parts; Use 'Format-DispatchPart' to create each part; .PARAMETER Attachments An array of attachments to include with the dispatch. Use 'Format-DispatchAttachment' to create each attachment. PS C:\> $attachments = @( (Format-DispatchAttachment -filepath 'c:\temp\file.png' -description 'This thing is broken') (Format-DispatchAttachment -filepath 'c:\temp\secondfile.jpg' -description 'This is broken too') ) .EXAMPLE PS C:\> $attachments = @( (Format-DispatchAttachment -filepath 'c:\temp\file.png' -description 'This thing is broken') (Format-DispatchAttachment -filepath 'c:\temp\secondfile.jpg' -description 'This is broken too') ) PS C:\> $Parts = @( (Format-DispatchPart -PartName ) PS C:\> Invoke-DispatchRequest -Credentials -Email 'Value2' -Branch 'Value3' -Customer 'Value4' -Track 'Value5' -ServiceTag 'Value6' -PrimaryContactName 'Value7' -PrimaryContactPhone 'Value8' -PrimaryContactEmail 'Value9' -CountryISOCode 'Value10' -City 'Value11' -State 'Value12' -ZipCode 'Value13' -AddressLine1 'Value14' -AddressLine2 'Value15' -AddressLine3 'Value16' -TimeZone 'Value17' -RequestCompleteCare $value18 -RequestReturnToDepot $value19 -RequestOnSiteTechnician $value20 -TroubleshootingNote 'Value21' .EXAMPLE PS C:\> $paramInvokeDispatchRequest = @{ Credentials = $Credentials TechEmail = "apiuser_us_tech01@uatmail.com" Branch = "US Group" Customer = "Round Rock Customer" Track = "Tier 1" ServiceTag = "BR5424J" PrimaryContactName = "One,Technician" PrimaryContactPhone = "1111111111" PrimaryContactEmail = "apiuser_us_tech01@uatmail.com" CountryISOCode = $true AddressLine1 = "1" AddressLine2 = "Main" AddressLine3 = "Street" City = "New York" State = "NY" ZipCode = "11111" TimeZone = "US/Central" RequestCompleteCare = $false RequestReturnToDepot = $false RequestOnSiteTechnician = $false TroubleshootingNote = "THIS IS A TEST" Attachments = @( (Format-DispatchAttachment -FilePath 'c:\Temp\file (1).xlsx') (Format-DispatchAttachment -FilePath "c:\Temp\file.xlsx" -Description "This is a file") ) Parts = @((Format-DispatchPart -PartNumber "MBD" -Quantity 1 -PPID "2148242621834394587")) } PS C:\> Invoke-DispatchRequest @paramInvokeDispatchRequest #> [CmdletBinding(DefaultParameterSetName = 'No Address Book', SupportsPaging = $false, SupportsShouldProcess = $false)] [OutputType([pscustomobject])] param ( [Parameter(Mandatory = $false, Position = 1)] [pscredential]$Credentials = (Get-Credential -message "Enter TechDirect Credentials:"), [Parameter(Mandatory = $true, Position = 2)] [Alias('Email')] [string]$TechEmail, [Parameter(Mandatory = $true, Position = 3)] [string]$Branch, [Parameter(Mandatory = $true, Position = 4)] [Alias('CustomerName')] [string]$Customer, [Parameter(Mandatory = $true, Position = 5)] [string]$Track, [Parameter(Mandatory = $true, Position = 6)] [Alias('SerialNumber')] [string]$ServiceTag, [Parameter(Mandatory = $true, Position = 7)] [string]$PrimaryContactName, [Parameter(Mandatory = $true, Position = 8)] [string]$PrimaryContactPhone, [Parameter(Mandatory = $true, Position = 9)] [string]$PrimaryContactEmail, [Parameter(Position = 10)] [string]$AlternateContactName, [Parameter(Position = 11)] [string]$AlternateContactPhone, [Parameter(Mandatory = $false, Position = 12)] [string]$ReferencePONumber, [Parameter(ParameterSetName = 'Using Address Book', Position = 13)] [string]$AddressBookName, [Parameter(ParameterSetName = 'No Address Book', Position = 13)] [string]$CountryISOCode, [Parameter(ParameterSetName = 'No Address Book', Mandatory = $false, Position = 14)] [string]$City, [Parameter(ParameterSetName = 'No Address Book', Mandatory = $false, Position = 15)] [string]$State, [Parameter(ParameterSetName = 'No Address Book', Mandatory = $false, Position = 16)] [string]$ZipCode, [Parameter(ParameterSetName = 'No Address Book', Mandatory = $false, Position = 17)] [string]$AddressLine1, [Parameter(ParameterSetName = 'No Address Book', Mandatory = $false, Position = 18)] [string]$AddressLine2, [Parameter(ParameterSetName = 'No Address Book', Mandatory = $false, Position = 19)] [string]$AddressLine3, [Parameter(ParameterSetName = 'No Address Book', Mandatory = $false, Position = 20)] [string]$TimeZone, [Parameter(Mandatory = $true, Position = 21)] [boolean]$RequestCompleteCare, [Parameter(Mandatory = $true, Position = 22)] [boolean]$RequestReturnToDepot, [Parameter(Mandatory = $true, Position = 23)] [boolean]$RequestOnSiteTechnician, [Parameter(Mandatory = $true, Position = 24)] [ValidateLength(0, 1000)] [string]$TroubleshootingNote, [Parameter(Mandatory = $true, Position = 25)] [array]$Parts, [Parameter(Position = 26)] [array]$Attachments ) $Username = ($PSboundparameters.Credentials).getnetworkcredential().Username $Password = ($PSboundparameters.Credentials).getnetworkcredential().Password $XML = @" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.dell.com"> <soapenv:Header/> <soapenv:Body> <api:CreateDispatch> <api:CreateDispatchRequest> <api:Login>$Username</api:Login> <api:Password>$Password</api:Password> <api:Dispatch> <api:TechEmail>$TechEmail</api:TechEmail> <api:Branch>$Branch</api:Branch> <api:Customer>$Customer</api:Customer> <api:Track>$Track</api:Track> <api:ServiceTag>$ServiceTag</api:ServiceTag> <api:PrimaryContactName>$PrimaryContactName</api:PrimaryContactName> <api:PrimaryContactPhone>$PrimaryContactPhone</api:PrimaryContactPhone> <api:PrimaryContactEmail>$PrimaryContactEmail</api:PrimaryContactEmail>`r`n "@ if ($AlternateContactName) { $XML += @" <api:AlternativeContactName>$AlternateContactName</api:AlternativeContactName> <api:AlternativeContactPhone>$AlternateContactPhone</api:AlternativeContactPhone>`r`n "@ } else { $XML += @" <api:AlternativeContactName/> <api:AlternativeContactPhone/>`r`n "@ } $XML += @" <api:ShipToAddress>`r`n "@ if ($AddressBookName) { $xml += @" <api:AddressBookName>$AddressBookName</api:AddressBookName>`r`n "@ } else { $xml += @" <api:AddressBookName/>`r`n "@ } $XML += @" <api:CountryISOCode>$CountryISOCode</api:CountryISOCode> <api:City>$City</api:City> <api:State>$State</api:State> <api:ZipPostalCode>$ZipCode</api:ZipPostalCode> <api:AddressLine1>$AddressLine1</api:AddressLine1>`r`n "@ if ($AddressLine2) { $XML += @" <api:AddressLine2>$AddressLine2</api:AddressLine2>`r`n "@ } else { $xml += "`t`t`t`t`t`t`t<api:AddressLine2/>`r`n" } if ($AddressLine3) { $xml += @" <api:AddressLine3>$AddressLine3</api:AddressLine3>`r`n "@ } else { $xml += "`t`t`t`t`t`t`t<api:AddressLine3/>`r`n" } $XML += @" <api:TimeZone>$TimeZone</api:TimeZone> </api:ShipToAddress> <api:ReferencePONumber>$ReferencePONumber</api:ReferencePONumber> <api:RequestCompleteCare>$($RequestCompleteCare.ToString().ToLower())</api:RequestCompleteCare> <api:RequestReturnToDepot>$($RequestReturnToDepot.ToString().ToLower())</api:RequestReturnToDepot> <api:RequestOnSiteTechnician>$($RequestOnSiteTechnician.ToString().ToLower())</api:RequestOnSiteTechnician> <api:TroubleshootingNote>$TroubleshootingNote</api:TroubleshootingNote> <api:OverrideDPSType/>`r`n "@ if ($Parts) { $XML += @" <api:Parts> $($Parts -join "`r`n") </api:Parts>`r`n "@ } else { $XML += "<api:Parts/>`r`n" } if ($Attachments) { $XML += @" <api:Attachments> $($Attachments -join "`r`n") </api:Attachments>`r`n "@ } else { $XML += "<api:Attachments/>`r`n" } $XML += @" </api:Dispatch> </api:CreateDispatchRequest> </api:CreateDispatch> </soapenv:Body> </soapenv:Envelope> "@ $DellToken = Get-TDAccessToken -Dispatch if ($DellToken.sandbox) { $endpoint = "https://apigtwb2cnp.us.dell.com/Sandbox/support/dispatch/v3/service" } else { $endpoint = "https://apigtwb2c.us.dell.com/PROD/support/dispatch/v3/service" } $Headers = @{ Authorization = "Bearer $($DellToken.access_token)" SOAPAction = "http://api.dell.com/IDispatchService/CreateDispatch" } try { $Response = Invoke-RestMethod $endpoint -Method Post -Body ([xml]$XML) -Headers $Headers -ContentType "text/xml" $Result = $Response.Envelope.Body.CreateDispatchResponse.CreateDispatchResult.DispatchCreateResult ####### We have to parse the XML response manually, since Powershell doesn't want to convert it to JSON natively $JSON = [pscustomobject]@{ DispatchID = $Result.DispatchID DispatchCode = $Result.DispatchCode Status = $Result.Status } return $JSON } catch { $result = $_.Exception.Response.GetResponseStream() $reader = New-Object System.IO.StreamReader($result) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() $response = $reader.ReadToEnd(); $ResponseMessage = ([xml]$Response).Envelope.Body.Fault $statuscode = $_.Exception.Response.StatusCode.value__ $ErrCategory = [system.management.automation.errorcategory]::InvalidOperation $ErrorRecord = New-Object System.Management.Automation.ErrorRecord($($ResponseMessage.faultstring), "$statuscode", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } function Get-DispatchStatus { <# .SYNOPSIS Get the status of a dispatch .DESCRIPTION The primary function to track status of the work order. Failure to provide sufficient failure evidence will result in rejection of dispatches. However, there can be other reasons for rejection. Status codes 'DSP', 'Issues' and 'QUE' indicate the WO has been approved by Dell for dispatch. A Dell dispatch number will be available for these status codes. Status code 'Shipped Parts' indicates the requested part(s) has/have been dispatched. Status code 'Dispatch Denied' indicates the request has been denied by Dell. Further action is required by the user on this dispatch request. They can contact Dell using phone or other means to proceed with the transaction. They can also use the ReSubmitDispatch() method to resubmit the request with more information. If a WO is denied more than three times, it is no longer valid and a new WO must be submitted. .PARAMETER Credentials Credential Object containing the Username/Password of the Technician .PARAMETER Code The Dispatch Code to query the status of. .EXAMPLE PS C:\> Get-DispatchStatus -Code 'Value1' .NOTES Additional information about the function. #> [CmdletBinding(ConfirmImpact = 'None', SupportsPaging = $false, SupportsShouldProcess = $false)] param ( [pscredential]$Credentials = (Get-Credential -message "Enter TechDirect Credentials:"), [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Alias('DispatchCode')] [string]$Code ) begin { $Username = ($PSboundparameters.Credentials).getnetworkcredential().Username $Password = ($PSboundparameters.Credentials).getnetworkcredential().Password $DellToken = Get-TDAccessToken -Dispatch if ($DellToken.sandbox) { $endpoint = "https://apigtwb2cnp.us.dell.com/Sandbox/support/dispatch/v3/service" } else { $endpoint = "https://apigtwb2c.us.dell.com/PROD/support/dispatch/v3/service" } $Headers = @{ Authorization = "Bearer $($DellToken.access_token)" SOAPAction = "http://api.dell.com/IDispatchService/GetDispatchStatus" } } process { $XML = @" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.dell.com"> <soapenv:Header/> <soapenv:Body> <api:GetDispatchStatus> <api:GetDispatchStatusRequest> <api:Login>$Username</api:Login> <api:Password>$Password</api:Password> <api:DispatchCode>$Code</api:DispatchCode> </api:GetDispatchStatusRequest> </api:GetDispatchStatus> </soapenv:Body> </soapenv:Envelope> "@ try { $Response = Invoke-RestMethod $endpoint -Method Post -Body ([xml]$XML) -Headers $Headers -ContentType "text/xml" $Result = $Response.Envelope.Body.GetDispatchStatusResponse.GetDispatchStatusResult.DispatchStatusResult ####### We have to parse the XML response manually, since Powershell doesn't want to convert it to JSON natively $JSON = [pscustomobject]@{ Result = $Result.Result Status = $Result.Status DPSNumber = $Result.DPSNumber DispatchCode = $Result.DispatchCode OrderDeniedReason = $Result.OrderDeniedReason } return $JSON } catch { $result = $_.Exception.Response.GetResponseStream() $reader = New-Object System.IO.StreamReader($result) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() $response = $reader.ReadToEnd(); $ResponseMessage = ([xml]$Response).Envelope.Body.Fault $statuscode = $_.Exception.Response.StatusCode.value__ $ErrCategory = [system.management.automation.errorcategory]::InvalidOperation $ErrorRecord = New-Object System.Management.Automation.ErrorRecord($($ResponseMessage.faultstring), "$statuscode", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } } function Get-PartsByServiceTag { <# .SYNOPSIS Get Replaceable Parts .DESCRIPTION Provides the list of all replaceable parts for a particular service tag. Use this function to query the list of parts that can be requested for dispatch. This function should be called only once per service tag and the results should be cached at the customer system. Output of this function will be a mandatory input for 'Invoke-DispatchRequest'. .PARAMETER Credentials Credential Object containing the Username/Password of the Technician .PARAMETER ServiceTag The Service Tag to get part info for. .EXAMPLE PS C:\> Get-PartsByServiceTag -ServiceTag 'BR5424J' .EXAMPLE PS C:\> 'BR5424J' | Get-PartsByServiceTag -Credentials $Credentials #> [CmdletBinding(ConfirmImpact = 'None', SupportsPaging = $false, SupportsShouldProcess = $false)] [OutputType([pscustomobject])] param ( [pscredential]$Credentials = (Get-Credential -message "Enter TechDirect Credentials:"), [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Alias('SerialNumber')] [string]$ServiceTag ) begin { $Username = ($PSboundparameters.Credentials).getnetworkcredential().Username $Password = ($PSboundparameters.Credentials).getnetworkcredential().Password $DellToken = Get-TDAccessToken -Dispatch if ($DellToken.sandbox) { $endpoint = "https://apigtwb2cnp.us.dell.com/Sandbox/support/dispatch/v3/service" } else { $endpoint = "https://apigtwb2c.us.dell.com/PROD/support/dispatch/v3/service" } $Headers = @{ Authorization = "Bearer $($DellToken.access_token)" SOAPAction = "http://api.dell.com/IDispatchService/GetPartsbyServiceTag" } } process { $XML = @" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.dell.com"> <soapenv:Header/> <soapenv:Body> <api:GetPartsbyServiceTag> <api:GetPartsbyServiceTag> <api:Login>$Username</api:Login> <api:Password>$Password</api:Password> <api:ServiceTag>$ServiceTag</api:ServiceTag> </api:GetPartsbyServiceTag> </api:GetPartsbyServiceTag> </soapenv:Body> </soapenv:Envelope> "@ try { $Response = Invoke-RestMethod $endpoint -Method Post -Body ([xml]$XML) -Headers $Headers -ContentType "text/xml" $Result = $Response.Envelope.Body.GetPartsbyServiceTagResponse.GetPartsbyServiceTagResult.PartsbyTagResult ####### We have to parse the XML response manually, since Powershell doesn't want to convert it to JSON natively #Ignore these parts, they're not things that would typically be replaced in any laptop $PartList = $Result.Parts.PartInformation $Parts = @() foreach ($Part in $PartList) { #Create a temporary object for each part, then add it in to the array of parts $tmp = [pscustomobject]@{ PartTypeCode = $Part.PartTypeCode PartNumber = $part.PartNumber PartDescription = $Part.PartDescription } $Parts += $tmp } #Return to Depot isn't in the response, even though it's in the documentation $tmp = [pscustomobject]@{ PartTypeCode = "Accessory" PartNumber = "RTD" PartDescription = "Return to Depot" } $Parts += $tmp $JSON = [pscustomobject]@{ Model = $Result.Model ModelDescription = $Result.ModelDescription Parts = $parts } return $JSON } catch { $result = $_.Exception.Response.GetResponseStream() $reader = New-Object System.IO.StreamReader($result) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() $response = $reader.ReadToEnd(); $ResponseMessage = ([xml]$Response).Envelope.Body.Fault $statuscode = $_.Exception.Response.StatusCode.value__ switch -Wildcard ($response) { "*Missing parameters*"{ $ErrCategory = [system.management.automation.errorcategory]::InvalidArgument } default{ $ErrCategory = [system.management.automation.errorcategory]::InvalidOperation } } $ErrorRecord = New-Object System.Management.Automation.ErrorRecord($($ResponseMessage.faultstring), "$statuscode", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } } function Get-BulkDispatch { <# .SYNOPSIS Provide Status Information in Bulk .DESCRIPTION Provides status information for a batch of work orders .PARAMETER Credentials Credential Object containing the Username/Password of the Technician .PARAMETER CreatedFromDate Contains a date constraint to limit the result set. Work Orders will only be returned if they were created after this date. .EXAMPLE PS C:\> Get-Dispatches -CreatedFromDate "01/01/2019" This command will return all dispatches created since 1 January 2019 00:00. .EXAMPLE PS C:\> Get-Dispatches -CreatedFromDate (Get-Date).addDays(-7) This command will return all dispatches created in the last 7 days, at the current time of day. #> [CmdletBinding(ConfirmImpact = 'None', SupportsPaging = $false, SupportsShouldProcess = $false)] [OutputType([pscustomobject])] param ( [pscredential]$Credentials = (Get-Credential -message "Enter TechDirect Credentials:"), [Parameter(Mandatory = $true)] [datetime]$CreatedFromDate ) $Username = ($PSboundparameters.Credentials).getnetworkcredential().Username $Password = ($PSboundparameters.Credentials).getnetworkcredential().Password $FormattedDate = (Get-date $CreatedFromDate -Format o) $XML = @" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.dell.com"> <soapenv:Header/> <soapenv:Body> <api:BulkDispatchesInquiry> <api:BulkDispatchesInquiryRequest> <api:Login>$Username</api:Login> <api:Password>$Password</api:Password> <api:CreatedFromDate>$FormattedDate</api:CreatedFromDate> <api:InStatuses></api:InStatuses> <api:Scope>All</api:Scope> </api:BulkDispatchesInquiryRequest> </api:BulkDispatchesInquiry> </soapenv:Body> </soapenv:Envelope> "@ $DellToken = Get-TDAccessToken -Dispatch if ($DellToken.sandbox) { $endpoint = "https://apigtwb2cnp.us.dell.com/Sandbox/support/dispatch/v3/service" } else { $endpoint = "https://apigtwb2c.us.dell.com/PROD/support/dispatch/v3/service" } $Headers = @{ Authorization = "Bearer $($DellToken.access_token)" SOAPAction = "http://api.dell.com/IDispatchService/BulkDispatchesInquiry" } try { $Response = Invoke-RestMethod $endpoint -Method Post -Body ([xml]$XML) -Headers $Headers -ContentType "text/xml" $Result = $Response.Envelope.Body.BulkDispatchesInquiryResponse.BulkDispatchesInquiryResult.DispatchInquiryResult.DispatchInquiryResult $Dispatches = @() foreach ($Dispatch in $Result) { $tmp = [pscustomobject]@{ Code = $Dispatch.Code DellDispatchNumber = $Dispatch.DellDispatchNumber Status = $Dispatch.Status } $Dispatches += $tmp } $Dispatches | ForEach-Object { $_ | Add-Member -MemberType NoteProperty -Name "Status Value" -Value $(Convert-TDStatusCode $_.status) } return $Dispatches } catch { $result = $_.Exception.Response.GetResponseStream() $reader = New-Object System.IO.StreamReader($result) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() $response = $reader.ReadToEnd(); $ResponseMessage = ([xml]$Response).Envelope.Body.Fault $statuscode = $_.Exception.Response.StatusCode.value__ $ErrCategory = [system.management.automation.errorcategory]::InvalidOperation $ErrorRecord = New-Object System.Management.Automation.ErrorRecord($($ResponseMessage.faultstring), "$statuscode", $ErrCategory, $null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } function Get-DeviceWarranty { <# .SYNOPSIS Get warranty information .DESCRIPTION Get the warranty information for a Dell device by providing one or more service tags .PARAMETER ServiceTag One or more Service Tags to get Warranty information for. (Max. 100) .EXAMPLE PS C:\> Get-DeviceWarranty -ServiceTags @("B68BK79","OE6W9MA") .EXAMPLE PS C:\> Get-DeviceWarranty -ServiceTags "B68BK79" #> [CmdletBinding(SupportsPaging = $false, SupportsShouldProcess = $false)] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [ValidateCount(0, 100)] [Alias('ServiceTags')] [array]$ServiceTag ) process { $URI = "https://apigtwb2c.us.dell.com/PROD/sbil/eapi/v5/assets?servicetags=" $URI = $URI + $($ServiceTag -join ",") $Token = (Get-TDAccessToken -Warranty) $Headers = @{ Authorization = "Bearer $($token.access_token)" } $response = Invoke-RestMethod -Method GET -Uri $URI -ContentType "application/json" -Headers $Headers $response | ForEach-Object {$_.shipdate = [datetime]$_.shipdate} return $response } } function Redo-DispatchRequest { <# .SYNOPSIS Resubmit a Dispatch Request .DESCRIPTION If a Dispatch is denied by Dell, further action is required on this dispatch request. When you check the status of SR using Get-DispatchStatus and get "Dispatch Denied", you can re submit the request adding more details. .PARAMETER Credentials Credential Object containing Technician Username/Password .PARAMETER Code The Dispatch Code associated with the denied dispatch .PARAMETER TroubleshootingNote The troubleshooting notes for this dispatch. This should explain, in detail, the reason for each part request. .PARAMETER Parts The parts requested in this dispatch. Use 'Format-DispatchPart' to create the xml object for each part. .EXAMPLE PS C:\> Redo-DispatchRequest -DispatchCode 'SR999999999' .NOTES Additional information about the function. #> [CmdletBinding(ConfirmImpact = 'Low', SupportsPaging = $false, SupportsShouldProcess = $false)] param ( [Parameter(Mandatory = $false)] [pscredential]$Credentials = (Get-Credential -message "Enter TechDirect Credentials:"), [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [Alias('DispatchCode')] [string]$Code, [ValidateNotNullOrEmpty()] [string]$TroubleshootingNote, [ValidateCount(1, 4)] [array]$Parts ) $Username = ($PSboundparameters.Credentials).GetNetworkCredential().UserName $Password = ($PSboundparameters.Credentials).GetNetworkCredential().Password $XML = @" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.dell.com"> <soapenv:Header/> <soapenv:Body> <api:ResubmitDispatch> <api:ResubmitDispatchRequest> <api:Login>$Username</api:Login> <api:Password>$Password</api:Password> <api:Dispatch> <api:DispatchCode>$Code</api:DispatchCode> <api:TroubleshootingNote>$TroubleshootingNote</api:TroubleshootingNote> <api:Parts> $Parts </api:Parts> </api:Dispatch> </api:ResubmitDispatchRequest> </api:ResubmitDispatch> </soapenv:Body> </soapenv:Envelope> "@ $DellToken = Get-TDAccessToken -Dispatch if ($DellToken.sandbox) { $endpoint = "https://apigtwb2cnp.us.dell.com/Sandbox/support/dispatch/v3/service" } else { $endpoint = "https://apigtwb2c.us.dell.com/PROD/support/dispatch/v3/service" } $Headers = @{ Authorization = "Bearer $($DellToken.access_token)" SOAPAction = "http://api.dell.com/IDispatchService/ResubmitDispatch" } try { $Response = Invoke-RestMethod $endpoint -Method Post -Body ([xml]$XML) -Headers $Headers -ContentType "text/xml" $Result = $Response.Envelope.Body.ResubmitDispatchResponse.ResubmitDispatchResult.DispatchCreateResult if ($Result.notes) { $ErrCategory = [system.management.automation.errorcategory]::InvalidData $ErrorRecord = New-Object System.Management.Automation.ErrorRecord($($Result.Notes.string), " ", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } else {return $Result} } catch { $result = $_.Exception.Response.GetResponseStream() $reader = New-Object System.IO.StreamReader($result) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() $response = $reader.ReadToEnd(); $ResponseMessage = ([xml]$Response).Envelope.Body.Fault $statuscode = $_.Exception.Response.StatusCode.value__ $ErrCategory = [system.management.automation.errorcategory]::InvalidOperation $ErrorRecord = New-Object System.Management.Automation.ErrorRecord($($ResponseMessage.faultstring), "", $ErrCategory, $Null) $PSCmdlet.ThrowTerminatingError($ErrorRecord) } } #region Helper Functions function Convert-FileToBase64 { param ( [Parameter(ValueFromPipeline = $true)] $Filepath ) process { $bufferSize = 9000 # should be a multiplier of 3 $buffer = New-Object byte[] $bufferSize $reader = [System.IO.File]::OpenRead($Filepath) $writer = "" $bytesRead = 0 do { $bytesRead = $reader.Read($buffer, 0, $bufferSize); $writer += ([Convert]::ToBase64String($buffer, 0, $bytesRead)) } while ($bytesRead -eq $bufferSize); $reader.Dispose() return $writer } } function Convert-TDStatusCode { <# .SYNOPSIS Convert a status code to text .DESCRIPTION Convert a status code to its text value. .PARAMETER Status The Staus Code to convert .EXAMPLE PS C:\> Convert-TDStatusCode -Status 'HOLD' #> [CmdletBinding(ConfirmImpact = 'None', SupportsPaging = $false, SupportsShouldProcess = $false)] [OutputType([string])] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Alias('StatusCode')] [string]$Status ) begin { $Codes = @{ "Request submitted to Dell and now under review" = @( "2H SBD" "APJ Queue" "BIL ERROR" "CAR" "Complete Care" "HOLD" "L2 Review" "L2 DISPATCH" "NBD" "NON LATIN 1" "NPO" "Parts Review" "Pending Supervisor" "PND" "Request Submitted" "Request Resubmitted" "Returned to Depot" "SBD" "SBD4" "TAG/CUSTOMER MISMATCH" ) "Claim Submitted" = @( "Claim Submitted" "Parts Returned/Claim Submitted" ) "CAD Deferred" = @("CAD-Deferred") "FED Queue" = @("FED") "Moved to Claims Process" = "Moved_to_Claims_Process" "Defective Part Received" = "Defective Part Received" "Request has been denied by Dell" = "Dispatch Denied" "Request has been approved by Dell" = @( "Issued" "DSP" "ORD" "QUE" ) "Create Dispatch/Place Request" = "START" "Pending Request 2" = "Pending 2" "Request has not been submitted to Dell" = "Pending Request" "Shipped Parts" = "Shipped Parts" } } Process { $codes.keys | % { if ($codes.$_ -contains "$status") { return $_ } } } } #endregion Helper Functions # SIG # Begin signature block # MIIQ/wYJKoZIhvcNAQcCoIIQ8DCCEOwCAQExDzANBglghkgBZQMEAgEFADB5Bgor # BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG # KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCBoP4YRYKYZrzY8 # rXzlRevdO++1X7/caBnq0aECWn0fKaCCC+8wggMIMIIB8KADAgECAhAeLeTkRNs8 # gEMIvpGunxhLMA0GCSqGSIb3DQEBCwUAMBwxGjAYBgNVBAMMEURaMDUzNDc5X0Nv # ZGVTaWduMB4XDTIwMDIwNjE5MDUzNloXDTIxMDIwNjE5MjUzNlowHDEaMBgGA1UE # AwwRRFowNTM0NzlfQ29kZVNpZ24wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK # AoIBAQD0az+EFRw2OiqtWw74lG8NlvxrQ695XftwhBkiNUyAk7hno3dJASd0Dp7Q # FhwS7JiGNBjVZEmoM7YbvPF3ePC4N7fYImvmRoHTeB8zXH9/VTFRTg2jrDXq5UpR # ppL3fGVxGQuB3+YrxmWPGqlaNS4N3uUmS0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