Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-D365LcsEnvironmentMetadata Unauthorized #564

Closed
stuartahonour opened this issue Aug 25, 2021 · 8 comments
Closed

Get-D365LcsEnvironmentMetadata Unauthorized #564

stuartahonour opened this issue Aug 25, 2021 · 8 comments

Comments

@stuartahonour
Copy link

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

  •         $resArray.AddRange($metadata.Data)
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : ArgumentNullException

Is this because I'm not setting the -BearerToken

How do I get the authentication to work?

@Splaxi
Copy link
Collaborator

Splaxi commented Aug 25, 2021

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
Copy link
Author

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
Copy link
Collaborator

Splaxi commented Aug 25, 2021

.... | FT

will do that for you.

@stuartahonour
Copy link
Author

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):
[Environment]::SetEnvironmentVariable("ServiceDrive", "C:", "Machine")

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

@stuartahonour
Copy link
Author

Here is the truncated output when using just |FT

image

@Splaxi
Copy link
Collaborator

Splaxi commented Aug 27, 2021

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
Copy link
Collaborator

Splaxi commented Aug 27, 2021

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
Copy link
Collaborator

Splaxi commented Sep 11, 2021

Let me know if you need anything else.

@Splaxi Splaxi closed this as completed Sep 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants