cEPRSSharepoint.psm1
enum Ensure { Absent Present } [DscResource()] class cEPRSInstallSharepoint { [DscProperty(Key)] [String] $ProductKey [DscProperty(Key)] [String] $Ensure [DscProperty(Key)] [String] $SetupFolderPath [DscProperty(Mandatory=$true)] [String] $ConfigXmlPath [DscProperty(Key)] [String] $SPModulePath [cEPRSInstallSharepoint] Get() { $Output= @{ ProductKey = $this.ProductKey Ensure = $this.Ensure SetupFolderPath = $this.SetupFolderPath ConfigXmlPath = $this.ConfigXmlPath SPModulePath = $this.SPModulePath } return $Output } [bool] Test() { $result = [System.Boolean]$false return $result } [void] Set() { #Write-Verbose "Use this cmdlet to deliver information about command processing." #Write-Debug "Use this cmdlet to write debug information while troubleshooting." $LogFile="Install_Sharepoint.log" try { $this.ProductKey=$this.ProductKey.trim() #$scriptDir = Get-Location -PSProvider .\SPModule $scriptDir="$($this.SPModulePath)" $moduleTargetDir = "$env:windir\System32\WindowsPowerShell\v1.0\Modules" $moduleSourceDir = "$scriptDir\SPModule.misc" Write-Verbose "Copying SPModule.misc from $moduleSourceDir to $moduleTargetDir" -Verbose # Copy the SPModule.misc folder to the powershell modules folder. Copy-Item $moduleSourceDir $moduleTargetDir -recurse -force $moduleSourceDir = "$scriptDir\SPModule.setup" Write-Verbose "Copying SPModule.setup from $moduleSourceDir to $moduleTargetDir" -Verbose # Copy the SPModule.setup folder to the powershell modules folder. Copy-Item $moduleSourceDir $moduleTargetDir -recurse -force Import-Module SPModule.misc Import-Module SPModule.setup #$sharepointscriptDir = $scriptDir.Path +"\SharePoint_Server_2010_SP1\setup.exe" Install-SharePoint -SetupExePath "$($this.SetupFolderPath)" -ConfigXmlPath "$($this.ConfigXmlPath)" -PIDKey $this.ProductKey #-ServerRole "SINGLESERVER" } catch [System.Exception] { Write-Verbose $_.Exception.message } <#Write-Verbose "Set Function execution starts" $files = Get-childItem $this.FilePath -Recurse foreach($var in $files) { switch($var.Extension) { ".trx" {Rename-Item $var.FullName $this.ResultFile} } } Write-Verbose "Execution ends"#> } } [DscResource()] class cEPRSNewSharePointFarm { [DscProperty(Key)] [String] $DBAccountName [DscProperty(Key)] [String] $Ensure [DscProperty(Key)] [String] $DBServerName [DscProperty(Key)] [String] $FarmName [DscProperty(Key)] [String] $DBAccountPassword [cEPRSNewSharePointFarm] Get() { $Output= @{ DBAccountName = $this.DBAccountName Ensure = $this.Ensure DBServerName = $this.DBServerName FarmName = $this.FarmName DBAccountPassword = $this.DBAccountPassword } return $Output } [bool] Test() { [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMo") | Out-Null [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMoExtended") | Out-Null [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMoEnum") | Out-Null [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null Write-Verbose "Connecting to $($this.DBServerName) server- START" $srvr = new-object ("Microsoft.SqlServer.Management.Smo.Server") "$($this.DBServerName)" Write-Verbose "Connecting to $($this.DBServerName) server- END" if($srvr) { return $false } else { return $true } } [void] Set() { #Write-Verbose "Use this cmdlet to deliver information about command processing." #Write-Debug "Use this cmdlet to write debug information while troubleshooting." $LogFile="NewSPFarm.log" try { Write-Verbose "set function execution starts......." $ScriptDir = Get-Location -PSProvider FileSystem $ModuleTargetDir = "$env:windir\System32\WindowsPowerShell\v1.0\Modules" $ModuleSourceDir = $ScriptDir.Path + "\SPModule\SPModule.misc" Write-Verbose "Copying SPModule.misc from $ModuleSourceDir to $ModuleTargetDir" # Copy the SPModule.misc folder to the powershell modules folder. Copy-Item $ModuleSourceDir $ModuleTargetDir -recurse -force $ModuleSourceDir = $ScriptDir.Path + "\SPModule\SPModule.setup" Write-Verbose "Copying SPModule.setup from $ModuleSourceDir to $ModuleTargetDir" # Copy the SPModule.setup folder to the powershell modules folder. Copy-Item $ModuleSourceDir $ModuleTargetDir -recurse -force Import-Module SPModule.misc Import-Module SPModule.setup $secpasswd = ConvertTo-SecureString "$($this.DBAccountPassword)" -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ("$($this.DBAccountName)", $secpasswd) New-SharePointFarm �DatabaseAccessAccount $mycreds �DatabaseServer $this.DBServerName �FarmName $this.FarmName Write-Verbose "set function execution ends......." } catch [System.Exception] { Write-Verbose $_.Exception.message } <#Write-Verbose "Set Function execution starts" $files = Get-childItem $this.FilePath -Recurse foreach($var in $files) { switch($var.Extension) { ".trx" {Rename-Item $var.FullName $this.ResultFile} } } Write-Verbose "Execution ends"#> } } [DscResource()] class cEPRSJoinSharePointFarm { [DscProperty(Key)] [String] $DBServerName [DscProperty(Key)] [String] $DBName [DscProperty(Key)] [String] $Passphrase [DscProperty(Key)] [String] $SPModulePath [cEPRSJoinSharePointFarm] Get() { $Output= @{ DBServerName = $this.DBServerName DBName = $this.DBName Passphrase = $this.Passphrase SPModulePath = $this.SPModulePath } return $Output } [bool] Test() { [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMo") | Out-Null [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMoExtended") | Out-Null [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMoEnum") | Out-Null [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null Write-Verbose "Connecting to $($this.DBServerName) server- START" $srvr = new-object ("Microsoft.SqlServer.Management.Smo.Server") "$($this.DBServerName)" Write-Verbose "Connecting to $($this.DBServerName) server- END" if($srvr) { return $false } else { return $true } } [void] Set() { #Write-Verbose "Use this cmdlet to deliver information about command processing." #Write-Debug "Use this cmdlet to write debug information while troubleshooting." $LogFile="NewSPFarm.log" try { Write-Verbose "set function execution starts......." $scriptDir="$($this.SPModulePath)" $moduleTargetDir = "$env:windir\System32\WindowsPowerShell\v1.0\Modules" $moduleSourceDir = "$scriptDir\SPModule.misc" Write-Verbose "Copying SPModule.misc from $moduleSourceDir to $moduleTargetDir" -Verbose # Copy the SPModule.misc folder to the powershell modules folder. Copy-Item $moduleSourceDir $moduleTargetDir -recurse -force $moduleSourceDir = "$scriptDir\SPModule.setup" Write-Verbose "Copying SPModule.setup from $moduleSourceDir to $moduleTargetDir" -Verbose # Copy the SPModule.setup folder to the powershell modules folder. Copy-Item $moduleSourceDir $moduleTargetDir -recurse -force Import-Module SPModule.misc Import-Module SPModule.setup $FarmPassphrase = (ConvertTo-SecureString $this.Passphrase -AsPlainText -force) Join-SharePointFarm -DatabaseServer $this.DBServerName -ConfigurationDatabaseName $this.DBName -Passphrase $FarmPassphrase Write-Verbose "set function execution ends......." } catch [System.Exception] { Write-Verbose $_.Exception.message } } } [DscResource()] class cEPRSNew_SharepointSite { [DscProperty(Key)] [String] $WebApplicationURL [DscProperty(Key)] [String] $Ensure [DscProperty(Key)] [String] $WebApplicationName [DscProperty(Key)] [String] $ApplicationPoolDisplayName [DscProperty(Key)] [String] $ContentDatabase [DscProperty(Key)] [String] $ApplicationPoolIdentity [DscProperty(Key)] [String] $ApplicationPoolPassword [cEPRSNew_SharepointSite] Get() { $Output= @{ WebApplicationURL = $this.WebApplicationURL Ensure = $this.Ensure WebApplicationName = $this.WebApplicationName ApplicationPoolDisplayName = $this.ApplicationPoolDisplayName ContentDatabase = $this.ContentDatabase ApplicationPoolIdentity = $this.ApplicationPoolIdentity ApplicationPoolPassword = $this.ApplicationPoolPassword } return $Output } [bool] Test() { $result = [System.Boolean]$false return $result } [void] Set() { #Write-Verbose "Use this cmdlet to deliver information about command processing." #Write-Debug "Use this cmdlet to write debug information while troubleshooting." $AppPoolStatus = $False Write-Verbose "Adding the powershell Snapins..." Try { #$ver = $Host | select version #if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"} Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue Import-Module WebAdministration -ErrorAction SilentlyContinue } catch [System.Exception] { Write-Verbose "Error in loading the sharepoint snapins..." Write-Verbose $_.Exception.message } Try { if(get-spwebapplication $this.WebApplicationURL -ErrorAction SilentlyContinue) { Write-Verbose "Aborting: Web Application $this.WebApplicationURL Already Exists" -ForegroundColor Red sleep 5 } else { if(Get-SPServiceApplicationPool $this.ApplicationPoolDisplayName -ErrorAction SilentlyContinue) { Set-Variable -Name AppPoolStatus -Value "IsSharePoint" -scope "script" } else { if((Test-Path IIS:\AppPools\$($this.ApplicationPoolDisplayName)).tostring() -eq "True") { Set-Variable -Name AppPoolStatus -Value "IsNotSharePoint" -scope "script" } } if($AppPoolStatus -eq "IsNotSharePoint") { Write-Verbose "Aborting: Application Pool $this.ApplicationPoolDisplayName already exists on the server and is not a SharePoint Application Pool" -ForegroundColor Red } elseif($AppPoolStatus -eq "IsSharePoint") { if($this.WebApplicationURL.StartsWith("http://")) { $HostHeader = $this.WebApplicationURL.Substring(7) $HTTPPort = "80" } elseif($this.WebApplicationURL.StartsWith("https://")) { $HostHeader = $this.WebApplicationURL.Substring(8) $HTTPPort = "443" } Set-Variable -Name AppPool -Value (Get-SPServiceApplicationPool $this.ApplicationPoolDisplayName) -scope "script" $WebApp = New-SPWebApplication -ApplicationPool $this.ApplicationPoolDisplayName -Name $this.WebApplicationName -url $this.WebApplicationURL -port $this.HTTPPort -DatabaseName $this.ContentDatabase -HostHeader $hostHeader $WebApp.update() } else { if(get-spmanagedaccount $this.ApplicationPoolIdentity) { Set-Variable -Name AppPoolManagedAccount -Value (Get-SPManagedAccount $this.ApplicationPoolIdentity | select username) -scope "Script" Set-Variable -Name AppPool -Value (New-SPServiceApplicationPool -Name $this.ApplicationPoolDisplayName -Account $this.ApplicationPoolIdentity) -scope "Script" } else { $AppPoolCredentials = New-Object System.Management.Automation.PSCredential $this.ApplicationPoolIdentity, (ConvertTo-SecureString $this.ApplicationPoolPassword -AsPlainText -Force) Set-Variable -Name AppPoolManagedAccount -Value (New-SPManagedAccount -Credential $AppPoolCredentials) -scope "Script" Set-Variable -Name AppPool -Value (New-SPServiceApplicationPool -Name $this.ApplicationPoolDisplayName -Account (get-spmanagedaccount $this.ApplicationPoolIdentity)) -scope "Script" } if($this.WebApplicationURL.StartsWith("http://")) { $HostHeader = $this.WebApplicationURL.Substring(7) $HTTPPort = "80" } elseif($this.WebApplicationURL.StartsWith("https://")) { $HostHeader = $this.WebApplicationURL.Substring(8) $HTTPPort = "443" } $WebApp = New-SPWebApplication -ApplicationPool $this.AppPool.Name -ApplicationPoolAccount $($this.AppPoolManagedAccount.Username) -Name $this.WebApplicationName -url $this.WebApplicationURL -port $HTTPPort -DatabaseName $this.ContentDatabase -HostHeader $hostHeader $WebApp.update() } } } catch [System.Exception] { Write-Verbose $_.Exception.message } } } [DscResource()] class cEPRSNew_InstallWSP { [DscProperty(Key)] [String] $WebApplicationURL [DscProperty(Key)] [String] $Ensure [DscProperty(Key)] [String] $solutionGUID [DscProperty(Key)] [String] $WSPPath [cEPRSNew_InstallWSP] Get() { $Output= @{ WebApplicationURL = $this.WebApplicationURL Ensure = $this.Ensure solutionGUID = $this.solutionGUID WSPPath = $this.WSPPath } return $Output } [bool] Test() { $result = [System.Boolean]$false return $result } [void] Set() { #Write-Verbose "Use this cmdlet to deliver information about command processing." #Write-Debug "Use this cmdlet to write debug information while troubleshooting." $solutionFile = Get-ChildItem "$this.WSPPath" $solutionFileName = $solutionFile.Name $solutionFilePath = $solutionFile.FullName $deploystatus = (Get-SPSolution | where-object {$_.Name -eq $solutionFileName}) if($deploystatus -ne $null) { Write-Verbose "Updated solution package" Update-SPSolution �Identity $solutionFileName -LiteralPath $solutionFilePath �GACDeployment } else { $solution = (Get-SPSolution | where-object {$_.Id -eq $this.solutionGUID}) if ($solution -eq $null) { Write-Verbose "adding solution package" Add-SPSolution $solutionFile.FullName } $solution = (Get-SPSolution -Identity $this.solutionGUID) if($solution.deployed -ne $true) { Write-Verbose "deploying solution package" Install-SPSolution -Identity $solutionFileName -WebApplication $this.WebApplicationURL -GACDeployment -force stsadm -o execadmsvcjobs $deploystatus = (Get-SPSolution | where-object {$_.Name -eq $solutionFileName}) Write-Verbose "Restarting Services-" iisreset } } Write-Verbose "set function execution ends......." catch [System.Exception] { Write-Verbose $_.Exception.message } } } [DscResource()] class cEPRSInstall_Reports { [DscProperty(Key)] [String] $xmlFilePath [DscProperty(Key)] [String] $Ensure [DscProperty(Key)] [String] $rdlFilePath [DscProperty(Key)] [String] $SharepointSiteURL [cEPRSInstall_Reports] Get() { $Output= @{ xmlFilePath = $this.xmlFilePath Ensure = $this.Ensure rdlFilePath = $this.rdlFilePath SharepointSiteURL = $this.SharepointSiteURL } return $Output } [bool] Test() { $result = [System.Boolean]$false return $result } [void] Set() { #Write-Verbose "Use this cmdlet to deliver information about command processing." #Write-Debug "Use this cmdlet to write debug information while troubleshooting." Function CreateReportLibrary { if($ReportLibraryName) { $ErrorActionPreference = "SilentlyContinue" $getreportobjects=$web.Lists[$ReportLibraryName] if(!$getreportobjects) { ##1. Creating report library $ReportlibraryTemplate = $web.listtemplates["Report Library"] $web.Lists.add($ReportLibraryName, $ReportLibraryDiscription, $ReportlibraryTemplate) $getreportobjects=$web.Lists[$ReportLibraryName] } else { Write-Verbose "Report library '$ReportLibraryName' already exists!" } $getreportobjects=$web.Lists[$ReportLibraryName] $ReportContentypes=$getreportobjects.ContentTypes["Report Builder Report"] if($ReportContentypes) { Write-Verbose "content type 'Report Builder Report' already exists on $ReportLibraryName" } else { ######2. Adding content types for report library $ctypeName1 = "Report Builder Report" $ctypeParent1 = $web.availablecontenttypes["Report Builder Report"] #Document $ctype = new-object Microsoft.SharePoint.SPContentType($ctypeParent1, $web.contenttypes, $ctypeName1) $ctype.Group = "Report Builder Report" $getreportobjects.ContentTypes.Add($ctype) } $ReportContentypes1=$getreportobjects.ContentTypes["Report Builder Model"] if($ReportContentypes1) { Write-Verbose "content type 'Report Builder Model' already exists on $ReportLibraryName" } else { $ctypeName2 = "Report Builder Model" $ctypeParent2 = $web.availablecontenttypes["Report Builder Model"] #Document $ctype = new-object Microsoft.SharePoint.SPContentType($ctypeParent2, $web.contenttypes, $ctypeName2) $ctype.Group = "Report Builder Model" $getreportobjects.ContentTypes.Add($ctype) ######2. Adding content types for report library END } } } Function UploadRDLFile { if($ReportLibraryName -and $Reportfilepath) { if($DBFoldername) { $web.AllowUnsafeUpdates = $true; $List = $web.Lists[$ReportLibraryName] $folders = $List.Folders if($folders.Count) { foreach($folder in $folders) { if($folder.name -eq $DBFoldername) { $cout=1 Write-Verbose "folder $foldername.name already exists!" break; } } if(!$cout) { $spFolder = $List.AddItem(��,[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$DBFoldername) $spFolder["Title"] = "$DBFoldername" $spFolder.Update() $folderslist = $List.Folders foreach($folders in $folderslist) { if($folders.name -eq $DBFoldername) { $folder=$folders break; } } } } else { $spFolder = $List.AddItem(��,[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$DBFoldername) $spFolder["Title"] = "$DBFoldername" $spFolder.Update() $folderslist = $List.Folders foreach($folders in $folderslist) { if($folders.name -eq $DBFoldername) { $folder=$folders break; } } } } ############uploading report file(.rdl)################# Start-SPAssignment -Global $web.AllowUnsafeUpdates = $true; $List = $web.Lists[$ReportLibraryName] if(!$DBFoldername) { $folder = $List.RootFolder $FileName = $Reportfilepath.Substring($Reportfilepath.LastIndexOf("\")+1) $File= Get-ChildItem $Reportfilepath [Microsoft.SharePoint.SPFile]$spFile = $web.GetFile($folder.Url + "/" + $File.Name) $fileStream = ([System.IO.FileInfo] (Get-Item $File.FullName)).OpenRead() #Add file Write-Verbose -NoNewLine -f yellow "Copying file " $File.Name " to " $folder.ServerRelativeUrl "..." [Microsoft.SharePoint.SPFile]$spFile = $folder.Files.Add($folder.Url + "/" + $File.Name, [System.IO.Stream]$fileStream, $true) Write-Verbose -f Green "...Success!" #Close file stream $fileStream.Close() Write-Verbose -NoNewLine -f yellow "Update file properties " $spFile.Name "..." $spFile.Item.Update() Write-Verbose -f Green "...Success!" $web.AllowUnsafeUpdates = $false; Stop-SPAssignment -Global } if($DBFoldername) { $FileName = $Reportfilepath.Substring($Reportfilepath.LastIndexOf("\")+1) $File= Get-ChildItem $Reportfilepath [Microsoft.SharePoint.SPFile]$spFile = $web.GetFile($folder.Url + "/" + $File.Name) $fileStream = ([System.IO.FileInfo] (Get-Item $File.FullName)).OpenRead() $ADDSub=$WEB.GetFolder($folder.Url) #Add file Write-Verbose -NoNewLine -f yellow "Copying file " $File.Name " to " $folder.ServerRelativeUrl "..." [Microsoft.SharePoint.SPFile]$spFile = $ADDSub.Files.Add($folder.Url +"/" + $File.Name,[System.IO.Stream]$fileStream,$true) Write-Verbose -f Green "...Success!" #Close file stream $fileStream.Close() Write-Verbose -NoNewLine -f yellow "Update file properties " $spFile.Name "..." $spFile.Item.Update() Write-Verbose -f Green "...Success!" $web.AllowUnsafeUpdates = $false; Stop-SPAssignment -Global } ############uploading report file(.rdl) END################# $web.AllowUnsafeUpdates = $true; $File= Get-ChildItem $Reportfilepath $reportSourceDefinitionName = $File.Name $list = $web.lists["$ReportLibraryName"] $item = $list.Items | ? {$_.Name -eq "$reportSourceDefinitionName"} $item.File.Publish("publishing") $web.AllowUnsafeUpdates = $false; } } Function CreateDBConnectionLibrary { if($DataConnectionLibraryName) { $ErrorActionPreference = "SilentlyContinue" $getdataobjects1=$web.Lists[$DataConnectionLibraryName] if(!$getdataobjects1) { ##1. Creating Database connection library $DataConnectionlibraryTemplate = $web.listtemplates["Data Connection Library"] $web.Lists.add($DataConnectionLibraryName, $DataConnectionDiscription, $DataConnectionlibraryTemplate) $getdataobjects1=$web.Lists[$DataConnectionLibraryName] } else { Write-Verbose "DB connection library '$DataConnectionLibraryName' already exists!" } $getdataobjects1=$web.Lists[$DataConnectionLibraryName] $dbContentypes=$getdataobjects1.ContentTypes["Report Data Source"] if($dbContentypes) { Write-Verbose "content type 'Report Data Source' already exists on $DataConnectionLibraryName" } else { ######2. Adding content types for data connection library $ctypeName3 = "Report Data Source" $ctypeParent3 = $web.availablecontenttypes["Report Data Source"] #Document $ctype = new-object Microsoft.SharePoint.SPContentType($ctypeParent3, $web.contenttypes, $ctypeName3) $ctype.Group = "Report Data Source" $getdataobjects1.ContentTypes.Add($ctype) ######2. Adding content types for data connection library END } } } Function UploadRSDSFile { if($DataConnectionLibraryName -and $Datasourcepath) { if($DBFoldername) { $web.AllowUnsafeUpdates = $true; $List = $web.Lists[$DataConnectionLibraryName] $folders = $List.Folders if($folders.Count) { foreach($folder in $folders) { if($folder.name -eq $DBFoldername) { $cout=1 Write-Verbose "folder $foldername.name already exists!" break; } } if(!$cout) { $spFolder = $List.AddItem(��,[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$DBFoldername) $spFolder["Title"] = "$DBFoldername" $spFolder.Update() $folderslist = $List.Folders foreach($folders in $folderslist) { if($folders.name -eq $DBFoldername) { $folder=$folders break; } } } } else { $spFolder = $List.AddItem(��,[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$DBFoldername) $spFolder["Title"] = "$DBFoldername" $spFolder.Update() $folderslist = $List.Folders foreach($folders in $folderslist) { if($folders.name -eq $DBFoldername) { $folder=$folders break; } } } } ############uploading report file(.rds)################# Start-SPAssignment -Global $web.AllowUnsafeUpdates = $true; $List = $web.Lists[$DataConnectionLibraryName] if(!$DBFoldername) { $folder = $List.RootFolder $FileName = $Datasourcepath.Substring($Datasourcepath.LastIndexOf("\")+1) $File= Get-ChildItem $Datasourcepath [Microsoft.SharePoint.SPFile]$spFile = $web.GetFile($folder.Url + "/" + $File.Name) $fileStream = ([System.IO.FileInfo] (Get-Item $File.FullName)).OpenRead() #Add file Write-Verbose -NoNewLine -f yellow "Copying file " $File.Name " to " $folder.ServerRelativeUrl "..." [Microsoft.SharePoint.SPFile]$spFile = $folder.Files.Add($folder.Url + "/" + $File.Name, [System.IO.Stream]$fileStream, $true) Write-Verbose -f Green "...Success!" #Close file stream $fileStream.Close() Write-Verbose -NoNewLine -f yellow "Update file properties " $spFile.Name "..." $spFile.Item.Update() Write-Verbose -f Green "...Success!" $web.AllowUnsafeUpdates = $false; Stop-SPAssignment -Global } if($DBFoldername) { $FileName = $Datasourcepath.Substring($Datasourcepath.LastIndexOf("\")+1) $File= Get-ChildItem $Datasourcepath [Microsoft.SharePoint.SPFile]$spFile = $web.GetFile($folder.Url + "/" + $File.Name) $fileStream = ([System.IO.FileInfo] (Get-Item $File.FullName)).OpenRead() $ADDSub=$WEB.GetFolder($folder.Url) #Add file Write-Verbose -NoNewLine -f yellow "Copying file " $File.Name " to " $folder.ServerRelativeUrl "..." [Microsoft.SharePoint.SPFile]$spFile = $ADDSub.Files.Add($folder.Url +"/" + $File.Name,[System.IO.Stream]$fileStream,$true) Write-Verbose -f Green "...Success!" #Close file stream $fileStream.Close() Write-Verbose -NoNewLine -f yellow "Update file properties " $spFile.Name "..." $ADDSub.Item.Update() Write-Verbose -f Green "...Success!" $web.AllowUnsafeUpdates = $false; Stop-SPAssignment -Global } ############uploading report file(.rds) END################# $web.AllowUnsafeUpdates = $true; $List = $web.Lists[$DataConnectionLibraryName] $folders = $List.Folders if($folders.Count) { foreach ($folder in $folders) { $folder["_ModerationStatus"] = 0 $folder.Update() } } $items = $list.Items if($items.Count) { foreach ($item in $items) { $item["_ModerationStatus"] = 0 $item.Update() } } $web.AllowUnsafeUpdates = $false; } } Add-PSSnapin Microsoft.SharePoint.Powershell Write-Verbose "Shrepoint site URL: $this.SharepointSiteURL" $web = Get-SPWeb $this.SharepointSiteURL $xml=New-Object XML $xml.Load($this.xmlFilePath) $RDLFiles=$xml.GetElementsByTagName("Tile") #$RDSFiles=$xml.GetElementsByTagName("SharedDataSource") #######################################Create,upload RDL files ############################# foreach($rdsfile in $RDLFiles) { $web.AllowUnsafeUpdates = $true; $ReportLibraryName=$rdsfile.LibraryName $ReportLibraryDiscription=$rdsfile.DisplayName if($ReportLibraryName) { CreateReportLibrary -ReportLibraryName $ReportLibraryName -SharepointSiteURL $this.SharepointSiteURL -ReportLibraryDiscription $ReportLibraryDiscription $RDSFilelist=$rdsfile.RDLFiles.RDLFile foreach($IndividualRDSFile in $RDSFilelist) { $Reportfilepath=$this.rdlFilePath+'\'+$IndividualRDSFile.name if($IndividualRDSFile.name) { UploadRDLFile -Reportfilepath $Reportfilepath -ReportLibraryName $ReportLibraryName -SharepointSiteURL $this.SharepointSiteURL } else { Write-Verbose "no files exists!" } } $Folderlist=$rdsfile.Folder if($Folderlist.Name) { foreach($folders in $Folderlist) { $DBFoldername=$folders.Name $RDSFilelist_Folder=$folders.RDLFiles.RDLFile foreach($IndividualRDSFile in $RDSFilelist_Folder) { $Reportfilepath=$this.rdlFilePath+'\'+$IndividualRDSFile.name if($IndividualRDSFile.name) { UploadRDLFile -Reportfilepath $Reportfilepath -ReportLibraryName $ReportLibraryName -SharepointSiteURL $this.SharepointSiteURL -DBFoldername $DBFoldername } else { Write-Verbose "no files exists!" } } } } } $web.AllowUnsafeUpdates = $false; } #######################################Create,upload RDL files END############################# } } |