function New-ReportServerDataSource { <# .SYNOPSIS Creates a new DataSource Using the Supplied Parameters #> [CmdletBinding()] param ( [Parameter(Position=0,Mandatory=$true)] [System.Web.Services.Protocols.SoapHttpClientProtocol]$proxy, [Parameter(Position=1,Mandatory=$true)] [string]$DataSourceName, [Parameter(Position=2,Mandatory=$true)] [string]$ConnectionString, [Parameter(Position=3,Mandatory=$true)] [string]$UserName, [Parameter(Position=4,Mandatory=$true)] [string]$Password, [Parameter(Position=5,Mandatory=$true)] [string]$ParentFolder, [Parameter(Mandatory=$false)] [Alias("Force")] [switch]$ForceOverwriteDataSources ) $proxyNameSpace = $proxy.GetType().Namespace $dataSource = New-Object("$proxyNameSpace.DataSourceDefinition") $dataSource.ConnectString = $ConnectionString $dataSource.Extension = "SQL" $dataSource.Enabled = $true $dataSource.CredentialRetrieval = [SSRS.CredentialRetrievalEnum]::Store $dataSource.ImpersonateUser = $false $dataSource.ImpersonateUserSpecified = $true $dataSource.WindowsCredentials = $true $dataSource.UserName = $UserName $dataSource.Password = $Password $propertyHash = @{ 'ConnectString' = $ConnectionString; 'UserName' = $UserName; 'Password' = $Password; 'WindowsCredentials' = $true; 'Enabled' = $true; 'Extension' = "SQL"; 'ImpersonateUser' = $false; 'ImpersonateUserSpecified' = $true; 'CredentialRetrieval' = [SSRS.CredentialRetrievalEnum]::Store; } $propertyCollection = $propertyHash.Keys.foreach{ @{ Name = $_; Value = $propertyHash[$_] } -as "${proxyNameSpace}.property" } $newDataSource = $proxy.CreateDataSource($DataSourceName, $ParentFolder, $ForceOverwriteDataSources.IsPresent, $dataSource, $propertyCollection) return $newDataSource }