d365collaborative / d365fo.tools

Tools used for Dynamics 365 Finance and Operations
MIT License
250 stars 102 forks source link

Get-D365LcsEnvironmentMetadata Unauthorized #564

Closed stuartahonour closed 3 years ago

stuartahonour commented 3 years ago

Trying to use Get-D365LcsEnvironmentMetadata -ProjectId "{Project ID Removed}" -LCSApiUri "https://lcsapi.lcs.dynamics.com" -TraverseAllPages -EnableException

It get the following Error

[Get-LcsEnvironmentMetadata] Error status code Unauthorized in request for getting the environment metadata a project in LCS. Unauthorized. | The remote server returned an error: (401) Unauthorized. WARNING: [16:49:59][Get-LcsEnvironmentMetadata] Stopping because of errors Exception calling "AddRange" with "1" argument(s): "Value cannot be null. Parameter name: collection" At line:15163 char:13

Is this because I'm not setting the -BearerToken

How do I get the authentication to work?

Splaxi commented 3 years ago

Hi.

You need to have an account and a registered application in place.

You can read this wiki, to get the prerequisite in place and then return to the environment Metadata.

https://github.com/d365collaborative/d365fo.tools/wiki/How-To-Download-Latest-Bacpac-From-Lcs

stuartahonour commented 3 years ago

Hi

Ok managed to get it to work by getting a bearerToken and using the folloiwng

Get-D365LcsEnvironmentMetadata -ProjectId "{ProjectID}" -LCSApiUri "https://lcsapi.lcs.dynamics.com" -TraverseAllPages -EnableException -BearerToken $Token

So now i just need to parse the output into a table

Splaxi commented 3 years ago

.... | FT

will do that for you.

stuartahonour commented 3 years ago

When using just |FT the output gets truncated

I also get these messages when running the command

Get-D365LcsEnvironmentMetadata -ProjectId $ProjectId -LCSApiUri "https://lcsapi.lcs.dynamics.com" -TraverseAllPages -EnableException -BearerToken $Token |FT

[09:12:05][] Unable to locate the %ServiceDrive% environment variable. It could indicate that the machine is either not configured with D365FO or that you have domain join ed a local Tier1. We have defaulted to c:\ [09:12:05][] This message will show every time you load the module. If you want to silence this message, please add the ServiceDrive environment variable by executing this command (remember to restart the console afterwards):

I assume this is because I'm running this on a none F&O Server?

stuartahonour commented 3 years ago

Here is the truncated output when using just |FT

image

Splaxi commented 3 years ago

Yes to the first question.

For the truncation, that is something you should look for within the powershell community and blog posts. I don't know your requirements and what you are trying to solve, but I'm confident that most things should be possible...

Splaxi commented 3 years ago

If you could explain what you're trying to achieve and what format you want the data / output to be in, I might be able to give a few and better pointers / directions.

Splaxi commented 3 years ago

Let me know if you need anything else.