When i try to add a masterpage to a web application using the following code :
$MasterPage = "C:\test.master"
$MasterPageName = [System.IO.Path]::GetFileName($masterpage);
$SpWebApp = Get-SpWebApplication $Url
$Spsite = $spWebApp.sites[0]
$web = $spSite.OpenWeb();
#Check if the page is already there.
$MasterPagelist = ($web).Lists |? {$_.Title -eq "Galerie met basispagina's"}
$item = $MasterPagelist.items |? {$_.Name -eq $MasterPageName}
$BaseMasterItem = $MasterPagelist.items |? {$_.Name -eq $BaseMasterPageName}
if($item -ne $null)
{
Delete-MasterPage $MasterPageName $spSite
}
$MasterPagelist.RootFolder.Files.Add($MasterPageName, [System.IO.File]::ReadAllBytes($MasterPage)) | out-null;
i get the following error:
Exception calling "Add" with "2" argument(s): ""
At line:1 char:37
+ $MasterPagelist.RootFolder.Files.Add <<<< ("test", $MasterPageBytes)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
The weird thing is that the error does not actually contain any usefull information. On my development farm this code works just fine, on my production farm it does not.
Any ideas on what could cause this behaviour?