Question

I want to disable "Require Use Remote Interfaces permission" of web application using power shell script.

Was it helpful?

Solution

I was not able to find any way to do that using the standard either PowerShell SnapIn or the CSOM/REST, so i looked under the covers. From tracing the code in the code-behind of that AuthenticationPage in the CA, here is a script that does decent job via Reflection.

Param( 
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [Microsoft.SharePoint.Administration.SPWebApplication] $webapp,

    [Parameter(Mandatory=$true)]
    [Microsoft.SharePoint.Administration.SPUrlZone] $zone,

    [Parameter(Mandatory=$true)]
    [bool] $RequiresUseRemoteAPIsPermission
)
[Microsoft.SharePoint.Administration.SPIisSettings] $newIisSettings = New-Object Microsoft.SharePoint.Administration.SPIisSettings

[Microsoft.SharePoint.Administration.SPIisSettings] $originalSettings = $webapp.IisSettings[$zone]

$nonPublicInstanceMethodBindingFlags = [Reflection.BindingFlags] "NonPublic,Instance"
$copyFromMethod = $newIisSettings.GetType().GetMethod("CopyFrom", $nonPublicInstanceMethodBindingFlags)
$copyFromMethod.Invoke($newIisSettings, $originalSettings)

$newIisSettings.ClientObjectModelRequiresUseRemoteAPIsPermission = $RequiresUseRemoteAPIsPermission

$UpdateAuthenticationSettingsMethod = $webapp.GetType().GetMethods($nonPublicInstanceMethodBindingFlags) |
    ?{ $_.Name -eq 'UpdateAuthenticationSettings' -and $_.GetParameters().Count -eq 2 }
$UpdateAuthenticationSettingsMethod.Invoke($webapp, @($zone, $newIisSettings));

This PowerShell script can only execute on the SharePoint server itself with Microsoft.SharePoint.PowerShell Snap-In running but it'll do the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top