When you’re working with PowerShell and SSRS, you may occasionally come across a script that works once, then just mysteriously decides not to work anymore on a second or third invocation. Or it may just not work period, even though you think the syntax is short and straightforward, and you know you’re not misspelling any syntax.
Please note I am running this on the PowerShell ISE, and PowerGUI – and tried on both PowerShell V2 and V3.
Common Task
What was driving me crazy (at some point, I promise I’m back to my sane self now) was trying to create a folder with property. The syntax is pretty straightforward, like this:
Import-Module SQLPS -DisableNameChecking; $ReportServerUri = "http://localhost/ReportServer/ReportService2010.asmx" $proxy = New-WebServiceProxy -Uri $ReportServerUri -UseDefaultCredential -Namespace SSRS ; $proxy $proxy.GetType().Namespace; #gives me SSRS #create a folder $property = New-Object "SSRS.Property" $property.Name = "Description" $property.Value = "This folder is for any HR related reports" #we need a property array to pass to the CreateFolder method $properties = New-Object "SSRS.Property[]" 1; $properties[0] = $property; $foldername = "HR_" + (Get-Date -format "yyyy-MMM-dd-hhmmtt"); $proxy.CreateFolder($foldername, "/", $properties);
Broken??
Should be simple, right? PowerShell says, nope, not today. You get this error:
Cannot convert argument "Properties", with value: "SSRS.Property",
for "CreateFolder" to type "SSRS.Property[]":
"Cannot convert the "SSRS.Property" value of type "SSRS.Property"
to type "SSRS.Property"."
At C:\Users\Administrator\Scripts\SSRS\SSRS.ps1:22 char:1
+ $proxy.CreateFolder($foldername, "/", $properties);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
Uh, what? Doesn’t that sound a little – wrong? It’s complaining about casting from SSRS.Property to SSRS.Property. It’s the same thing!
Read the rest of this entry »







