I am new to powershell
Using a power shell script to deploy my SSRS reports
I have run into weird problem
extracts from script
----------------------------------
Create Data source function
------------------------------------
function New-SSRSDataSource ($Proxy,[string]$RdsPath,[string]$Folder,[switch]$Overwrite) {
Write-Verbose "New-SSRSDataSource -RdsPath $RdsPath -Folder $Folder"
$Folder = Normalize-SSRSFolder -Folder $Folder
[xml]$Rds = Get-Content -Path $RdsPath
$ConnProps = $Rds.RptDataSource.ConnectionProperties
$Definition = New-Object -TypeName SSRS.ReportingService2010.DataSourceDefinition
$Definition.ConnectString = $ConnProps.ConnectString
$Definition.Extension = $ConnProps.Extension
if ([Convert]::ToBoolean($ConnProps.IntegratedSecurity)) {
$Definition.CredentialRetrieval = 'Integrated'
}
$hash =@{
Name = $Rds.RptDataSource.Name
Path = $Folder + '/' + $Rds.RptDataSource.Name
}
$DataSource = New-Object -TypeName PSCustomObject -Property $hash
if ( $Overwrite -or $Proxy.GetItemType($DataSource.Path) -eq 'Unknown') {
$Proxy.CreateDataSource($DataSource.Name, $Folder, $Overwrite, $Definition, $null)
}
return $DataSource
}
----------------------------------
where Its referenced
-----------------------------------
$DataSourcePaths = @{}
$Project.SelectNodes('Project/DataSources/ProjectItem') |
ForEach-Object {
$RdsPath = $ProjectRoot | Join-Path -ChildPath $_.FullPath
"$RdsPath"
$DataSource = New-SSRSDataSource -Proxy $Proxy -RdsPath $RdsPath -Folder $DataSourceFolder
$DataSource|Out-GridView
$DataSourcePaths.Add($DataSource.Name,$DataSource.Path)
}
I have two Items in 'ProjectItem' node so essentially for loop should execute for two times
current behaivour
when I execute script for the first time
following are results from both grid view and error message at powershell prompt
Grid View
0SSRS.ReportingService2010.CatalogItemSSRS.ReportingService2010.CatalogItem
1@{Name=Verification Relational DS; Path=/Data Sources/Verification Relational DS}System.Management.Automation.PSCustomObject
Prompt
ForEach-Object : Property 'Name' cannot be found on this object. Make sure that it exists.
At C:\Users\prabhakar.munugala\Documents\Visual Studio 2010\Projects\DVSDashBoard\DVSDashBoard\Deploy-SSRS
68 char:19
+ ForEach-Object <<<< {
+ CategoryInfo : InvalidOperation: (.:OperatorToken) [ForEach-Object], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Commands.ForEachObjectCommand
When I execute it second time
it would have two grid views as '$DataSourcePaths.Add($DataSourcePaths.Add($DataSource.Name,$DataSource.Path)'
has got 'Name' and 'Path' properties
But it fails on the second data source
below are results
GridView1
Verification Relational DS/Data Sources/Verification Relational DS
GridView2
0SSRS.ReportingService2010.CatalogItemSSRS.ReportingService2010.CatalogItem
1@{Name=VerificationCube; Path=/Data Sources/VerificationCube}System.Management.Automation.PSCustomObject
Prompt
ForEach-Object : Property 'Name' cannot be found on this object. Make sure that it exists.
At C:\Users\prabhakar.munugala\Documents\Visual Studio 2010\Projects\DVSDashBoard\DVSDashBoard\Deploy-S
68 char:19
+ ForEach-Object <<<< {
+ CategoryInfo : InvalidOperation: (.:OperatorToken) [ForEach-Object], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Commands.ForEachObjectCommand
When I run for the third time
every thing is good
Below are results
GridView1
VerificationCube/Data Sources/VerificationCube
GridView2
Verification Relational DS/Data Sources/Verification Relational DS
and Script executes well
Issue :- Returned PSObject , on initial run is not returning the expected value
any help would be appreciated