Hello,
In short my problem is that when I run a PowerShell script to create New SPWebApplication on the server where SharePoint farm is configured all is working fine.
When I run the script from a remote machine I get many problems such as "Method invocation failed because [Deserialized.Microsoft.SharePoint.Administration.SPWebApplication] doesn't contain a method named 'Update'", but also when i try to create policy
for a User or Group on that SPWebApplication. such as:
$policy = $SPMissionWebApp.Policies.Add($userOrGroup, $displayName)`
I Get the next error:
Cannot find an overload for "Add" and the argument count: "2".
Here is a part of the script:
$UserName = "domain\administrator"
$Password = "password01"
$SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName,$SecurePassword
#building the remote session
$session = New-PSSession "RemoteSharePointServerName" -Authentication Credssp -Credential $Credential
Invoke-Command $session {Add-PSSnapin Microsoft.SharePoint.PowerShell}
Import-PSSession -Session $session -AllowClobber
Start-SPAssignment -Global
$portalAppServer = Get-SPServer
$farm = Get-SPFArm
$WebAppName = "Name1"
$WebAppHostHeader = $portalAppServer.Address
$WebAppPort = 80
$WebAppAppPool = $WebAppName +"_AppPool"
$WebAppAppPoolAccount = Get-SPManagedAccount
$WebAppDatabaseName = "$WebAppName"
$WebAppDatabaseServer = $portalAppServer
# Create a new Sharepoint WebApplication
$SPNewWebApp = New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader
$WebAppHostHeader -URL ("http://" + $WebAppHostHeader) -ApplicationPool $WebAppAppPool -ApplicationPoolAccount $WebAppAppPoolAccount.DisplayName -DatabaseName $WebAppDatabaseName -ErrorVariable +err
#till here all is working fine and the new application is created
if($SPNewWebApp -ne $null)
{
$SPNewWebApp.SuiteBarBrandingElementHtml = " $WebAppName"
#this has failed with the next error: Method invocation failed because
#[Deserialized.Microsoft.SharePoint.Administration.SPWebApplication] doesn't contain a method
#named 'Update'
$SPNewWebApp.Update()
$userOrGroup = $UserName
$displayName = "Description of the Owner"
#this has failed too with: Cannot find an overload for "Add" and the argument count: "2".
#the Policies.Add method accept only one argument
$policy = $SPNewWebApp.Policies.Add($userOrGroup, $displayName)
$policyRole = $SPMissionWebApp.PolicyRoles.GetSpecialRole
([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullControl)
$policy.PolicyRoleBindings.Add($policyRole) `
#this has failed too
$SPMissionWebApp.Update()
}
Is there a difference between the remote loaded SharePoint SNAPIN library and this one on the server. IS that a bug when proxy are created or is a problem in my script. What I'm doing wrong in this case. Please help.
Thank you in advance.
Kind regards. Alex
developer