This is my first question at Stack Overflow, and I really hope I am doing this right. If not, please let me know and I will correct.
I run Office365 Build 16.0.12527.20612 32 bit on Windows 10 64 bit.
I have searched for 2 days and tried different approaches, but not succeeded. I am familiar with VBA and have coded some macros. I have a list of computer names and serial numbers in Excel. I have a powershell script that can get computer information from Dell. It is the warranty information that is of interest. Preferably I would like to write a macro that does the same thing as the script. Here is the powershell script:
$ServiceTag = "A1B2C3D4"
Try {
# Get Access Token - expires in 3600 seconds
$accessTokenEndpointUrl = "https://apigtwb2c.us.dell.com/auth/oauth/v2/token"
$requestBody = @{
grant_type = "client_credentials"
client_id = "123456789012345" # api key
client_secret = "098765432109876" # api secret
}
write-output "requestbode: $requestBody"
$token = (Invoke-RestMethod -uri $accessTokenEndpointUrl -Headers @{ } -Method Post -Body $requestBody).Access_token
write-output "Token: $token"
# url for api warranty query - tag is comma seperated list of service tags
$url = "https://apigtwb2c.us.dell.com/PROD/sbil/eapi/v5/asset-entitlements"
$headers = @{"Authorization" = "Bearer $token" }
$body = @{
servicetags = $ServiceTag
}
$resp = Invoke-RestMethod -Uri $url -Headers $headers -Method Get -Body $body
write-output $resp
}
Catch {
Write-Host $($_.Exception.Message)
}
I have not been able to make call to the webservice correctly. I didn’t save any of the macros as they didn't work. I was able to get as far as to call the service but got response that "data missing or duplicate". It is the requestBody I think I am not able to create correctly. Then I thought that I could try to run the script from VBA and output to a file, then read the file in VBA. I tried different ways I found on stack overflow, but I either get a sidebyside error (eventlog referring to powershell.exe) or permission denied depending on which sample I try. I could from same macro start other programs, like notepad.
I would appreciate if anybody here could help.
I tried this:
Sub RunPS()
strCommand = "Powershell.exe - ExecutionPolicy ByPass -File ""D:\temp\DellCheck.ps1"""
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run (strCommand)
End Sub
I get this at WshShell.Run(strCommand): error