Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

PowerShell Script Get-SPOProvisioningTemplate fails if no output file exists #921

Closed
NPrice99 opened this issue Jun 11, 2015 · 16 comments
Closed

Comments

@NPrice99
Copy link

If you type in Get-SPOProvisioningTemplate -Out "C:\MyOutputfile.xml" then the command fails "file not found" if the output file "C:\MyOutputfile.xml" does not already exist.

If you create a blank file "C:\MyOutputfile.xml" and rerun command it now works and asks you if you want to overwrite the existing file.
If you say "Y" it deletes the existing file and then says "File not found" and exits. If you say "no" the command exits.
If you add -Force it fails "File Not found" .

@erwinvanhunen
Copy link
Member

Can you double check you have the appropriate rights to create a file in root of your C: drive (according the example you posted in the issue you try to create a file in the root of your drive). I cannot reproduce the issue, in my case it's always creating file.

@NPrice99
Copy link
Author

Created blank file using notebook successfully. Also tried running powershell script as administrator and got same results.

get-spprovisioningtemplateevidence

I pulled down OfficeDev.Core dev branch down yesterday afternoon

@erwinvanhunen
Copy link
Member

this is strange. I have not changed anything in that part of the cmdlet since the last release. The only thing I can think of is that's an access right issue...

@NPrice99
Copy link
Author

If I run the equivalent command in C# and visual studio to the same place it works OK. It must have permissions because it deletes the blank file I put in when I use the -Force option before it says file not found. I have tried using different places including my documents library which I certainly have access to.

@NPrice99
Copy link
Author

The SharePoint Online version works OK. Its the On-Premises version which is not working. I ran both on the same laptop, to the same file location.

@kilasuit
Copy link

Looking at the Screen shot your calling a script within the PowerShell window by dot sourcing - Have you tried to run PowerShell as Administrator with this?

I only ask as on occasions with certain directories you need to be running in the privileged mode to be able to make any changes in that directory - due to UAC

@NPrice99
Copy link
Author

I have managed to run this successfully on the x64 version of the command. The. x64 online and on-premises works fine. the x86 online version works fine, the x86 on-Premises version does not work. I hope that helps.

@NPrice99
Copy link
Author

Found the issue ! If I type at the command prompt Get-SPOProvisioningTemplate https://......... -Out C:\Mytemplate it works. If I put Get-SPOProvisioningTemplate etc into a .ps1 file and call . .\mybatchfile.ps1 it fails. Whether it is in an administrator PowerShell windows or just an ordinary one.

@azakhodin
Copy link

Hi, I tried to run this command. I could tell that is running (status bar indicates it), then I get the following error
error

@NPrice99
Copy link
Author

Hi
You do not have the assembly NewtonSoft.Json in your path. Hence PowerShell command cannot find it. ALso your slashes are the wrong way should be top left to bottom right. Go to the environment variables and find out where the environment variable "Path" is pointing to and make sure that the file NewtonSoft.Json s there.

@azakhodin
Copy link

Thank you for your reply. I changed the slashes and added folder with Newtonsoft.json to the path (this folder C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell contains Newtonsoft.json) .I still get the same error, even it seems that script is running
error1
error3

@erwinvanhunen
Copy link
Member

try to full uninstall the cmdlets through the Control Panel and reinstall them by first downloading them from https://github.com/officedev/pnp-powershell/releases. I checked the latest build and both the V15 and V16 version install the Newtonsoft.Json dll in the correct folder.

@inputoutputcode
Copy link

I get the same experience as NPrice99. I tested the code from the PowerShell Command Get-SPOProvisioningTemplate in separate console project with just C# and OfficeDevPnP.Core, this works. The version (source code and installer package) is downloaded with the GitHub Windows Desktop Tool. I saw a strange behavior: I can select the Schema V201508 in PowerShell, but cannot see where it is in the installed DLLs.

@inputoutputcode
Copy link

I solved the issue with the schema, two versions was installed on the system. I attached the debugger and saw that the exception occurs in line 115 of GetProvisiongTemplate.cs, in the method OfficeDevPnP.PowerShell.Commands.Branding.GetProvisioningTemplateXML(XMLPnPSchemaVersion schema, string path), the SelectedWeb property throws the FileNotFoundException.
So from the callstack it seems that OfficeDevPnP.PowerShell.Commands.SPOWebCmdlet.GetWeb() has problems to get the web with a valid URL, the same URL is accessible by the browser.

Any ideas?

@inputoutputcode
Copy link

Hmm, first I got the innerexception "The Push Notifications feature is not activated on the site 'http://portal.chrpap.com'", so I activated it through Enable-SPFeature -Identity 41e1d4bf-b1a2-47f7-ab80-d5d6cbba3092 -URL "http://portal.chrpap.com". But get another exception from OfficeDevPnP.PowerShell.Commands.WebExtensions.GetWebByUrl() in line 25 (clientContext.ExecuteQueryRetry()).

Could it be that it is only possible to get webs from the same site collection?

I found it: the problem is the site.OpenWeb(url) method.
For the url parameter there are the following rules: Specifies the server-relative URL or web-relative URL of the site to open. If strurl is empty, the top-level site must be opened.
Reference: https://msdn.microsoft.com/EN-US/library/office/microsoft.sharepoint.client.site.openweb.aspx

So in my example I using one site collection for one web, every time. If I connect with the CMDLet Connect-SPOnline to my template site and use for Get-SPOProvisioningTemplate the web parameter with an empty string, then everything works fine.

It would be nice the make the URL switch in OfficeDevPnP.Core directly.

@NPrice99
Copy link
Author

Hi Patrick
What was the fix ?
Regards
Nigel

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants