1

I'm trying to fix the language of a PnP PowerShell request. Specifically, I'd like to extract site scripts from a web in a neutral language.

Here's what I tried :

$cnx = Connect-PnPOnline -ReturnConnection ` -Url https://somewhere.sharepoint.com/sites/overtherainbow ` -ClientId a165e590-a591-4897-cd27-929ccddb9908 ` -ClientSecret "supersecret" Register-ObjectEvent -InputObject $cnx.Context -EventName ExecutingWebRequest -Action { param( [object]$sender, [Microsoft.SharePoint.Client.WebRequestEventArgs]$args ) [void] $args.WebRequestExecutor.WebRequest.Headers.Add("Accept-Language", "en-us") } Get-PnPSiteScriptFromList -Url https://somewhere.sharepoint.com/sites/overtherainbow/SitePages -Connection $cnx 

However, the result isn't in english, but in the default site language.

Monitoring the network using Fiddler doesn't show the expected header at all.

How to fix that ? Is there an alternative to reach my goal ?

PS: if I try to execute the REST method using Insomnia, I get what I want to achieve. The header is present

1 Answer 1

0

Thanks for this post. Helped me find a missing piece to something I was working on.

As for the question... the property is RequestHeaders on the WebRequestExecutor type itself.

[void] $args.WebRequestExecutor.RequestHeaders.Add("Accept-Language", "en-us") 

Essentially the same thing here:

$Ctx.add_ExecutingWebRequest({ param($Source, $EventArgs) $request = $EventArgs.WebRequestExecutor.RequestHeaders $request.Add("Accept-Language","en-us") }) 

Hope that helps, even if it's over a year old.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.