I have a PnP PowerShell script I have used successfully for some time. It has been a few months since I last used it so I do not know when it last worked.
Background:
I have a script I use to export the custom fields of a list. This was due to migrations from SP2019 and poor naming of list fields. For select scenarios, I would recreate the list from scratch.
I would export the custom fields from a list using this snippet:
foreach($field in $ListFields){
$($field.Title + "," + $field.InternalName + "," + $field.TypeDisplayName + "," + $field.SchemaXml) >> $OutputFile
}
The csv file would have the internal names cleaned up leveraging find/replace.
Once I have the fields cleaned up, I run a PnP script to run thru the fields in the CSV.
Bug:
When the script runs currently, it is throwing an error when executing this statement:
Add-PnPFieldFromXml -List $ListName -FieldXml $xml
throws the following error:
Unexpected response from the server. The content type of the response is "text/plain; charset=utf-8". The status code is "NotFound".
Get-PnpException provides the following:
Message : Unexpected response from the server. The content type of the response is "text/plain; charset=utf-8". The status code is
"NotFound".
Stacktrace : at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord()
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
ScriptLineNumber : 9
I looked up the command from here to verify nothing had changed https://pnp.github.io/powershell/cmdlets/Add-PnPFieldFromXml.html
On this page, there is an example to run:
$xml = '<Field Type="Text" Name="PSCmdletTest" DisplayName="PSCmdletTest" ID="{27d81055-f208-41c9-a976-61c5473eed4a}" Group="Test" Required="FALSE" StaticName="PSCmdletTest" />'
Add-PnPFieldFromXml -List "Demo List" -FieldXml $xml
I executed the above for my site's list and got the same error.
I also checked to make sure I am on the latest release: 3.1.0 by running the command to update it.
Update-Module PnP.Powershell -Scope CurrentUser
Thanks!
I have a PnP PowerShell script I have used successfully for some time. It has been a few months since I last used it so I do not know when it last worked.
Background:
I have a script I use to export the custom fields of a list. This was due to migrations from SP2019 and poor naming of list fields. For select scenarios, I would recreate the list from scratch.
I would export the custom fields from a list using this snippet:
The csv file would have the internal names cleaned up leveraging find/replace.
Once I have the fields cleaned up, I run a PnP script to run thru the fields in the CSV.
Bug:
When the script runs currently, it is throwing an error when executing this statement:
Add-PnPFieldFromXml -List $ListName -FieldXml $xmlthrows the following error:
Unexpected response from the server. The content type of the response is "text/plain; charset=utf-8". The status code is "NotFound".Get-PnpException provides the following:
I looked up the command from here to verify nothing had changed https://pnp.github.io/powershell/cmdlets/Add-PnPFieldFromXml.html
On this page, there is an example to run:
I executed the above for my site's list and got the same error.
I also checked to make sure I am on the latest release: 3.1.0 by running the command to update it.
Update-Module PnP.Powershell -Scope CurrentUserThanks!