Uso Powershell per eseguire diversi report su Microsoft SQL Report Services e per salvare i risultati in un documento Word. Ho uno script con le funzioni che gestiscono le comunicazioni con il server di report:SSRS e PowerShell: Parametro non accettato
## File "qrap-functions.ps1"
function GetRSConnection($server, $instance)
{
$User = "xxxx"
$PWord = ConvertTo-SecureString -String "yyyy" -AsPlainText -Force
$c = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
$reportServerURI = "http://" + $server + "/" + $instance + "/ReportExecution2005.asmx?WSDL"
$RS = New-WebServiceProxy -Class 'RS' -NameSpace 'RS' -Uri $reportServerURI -Credential $c
$RS.Url = $reportServerURI
return $RS
}
function GetReport($RS, $reportPath)
{
$reportPath = "/" + $reportPath
#$reportPath
$Report = $RS.GetType().GetMethod("LoadReport").Invoke($RS, @($reportPath, $null))
$parameters = @()
$RS.SetExecutionParameters($parameters, "nl-nl") > $null
return $report
}
function AddParameter($params, $name, $val)
{
$par = New-Object RS.ParameterValue
$par.Name = $name
$par.Value = $val
$params += $par
return ,$params
}
function GetReportInFormat($RS, $report, $params, $format, $saveas)
{
$deviceInfo = "<DeviceInfo><NoHeader>True</NoHeader></DeviceInfo>"
$extension = ""
$mimeType = ""
$encoding = ""
$warnings = $null
$streamIDs = $null
$RS.SetExecutionParameters($params, "nl-nl") > $null
$RenderOutput = $RS.Render($format,
$deviceInfo,
[ref] $extension,
[ref] $mimeType,
[ref] $encoding,
[ref] $warnings,
[ref] $streamIDs
)
$Stream = New-Object System.IO.FileStream($saveas), Create, Write
$Stream.Write($RenderOutput, 0, $RenderOutput.Length)
$Stream.Close()
}
allora, ho uno script che esegue un report contenente i dati trimestrali finanziari. Questo script funziona benissimo:
## File "qrap-financieel.ps1"
. "./qrap-functions.ps1"
$saveas = "e:\test\financieel.doc"
$RS = GetRSConnection -server "MSZRDWH" -instance "reportserver_acc"
$report = GetReport -RS $RS -reportPath "kwartaalrapportage/kwartaalrapportage financieel"
$params = @()
$kwartaal = "[Periode Maand].[Jaar Kwartaal].&[2015-2]"
$kptc = "[Kostenplaats].[Team code].&[2003]"
$params = AddParameter -params $params -name "PeriodeMaandJaarKwartaal" -val $kwartaal
$params = AddParameter -params $params -name "KostenplaatsTeamcode" -val $kptc
GetReportInformat -RS $RS -report $report -params $params -format "WORD" -saveas $saveas
I valori per $kwartaal
e $kptc
sono hard-coded qui, ma sono parametri nella versione attuale di questo script. Oltre al trimestre finanziario, abbiamo altri tre rapporti trimestrali che devono essere pubblicati da questo script. Due di questi funzionano bene, nel quarto non riesco a ottenere uno dei parametri corretti. Lo script per quello è:
## File "qrap-zorglog.ps1"
. "./qrap-functions.ps1"
$RS = GetRSConnection -server "MSZRDWH" -instance "reportserver_acc"
$report = GetReport -RS $RS -reportPath "kwartaalrapportage/kwartaalrapportage zorglogistiek"
$s = "Urologie"
$saveas = "e:\test\ZL Urologie.doc"
$params = @()
$kwartaal = "[Periode Maand].[Jaar Kwartaal].&[2015-2]"
$params = AddParameter -params $params -name "HoofdspecialismeSpecialismeOms" -val "[Hoofdspecialisme].[Specialisme Oms].&[$s]"
$params = AddParameter -params $params -name "PeriodeMaandJaarKwartaal" -val $kwartaal
$params = AddParameter -params $params -name "WachttijdenSpecialismeSpecialisme" -val "[Wachttijden Specialisme].[Specialisme].&[$s]"
$params = AddParameter -params $params -name "SpecialisatieGroeperingSpecialisatieGroeperingOms" -val "[Specialistie Groepering].[Specialistie Groepering Oms].&[$s]"
$params = AddParameter -params $params -name "AanvragendSpecialismeSpecialismeOms" -val "[AanvragendSpecialisme].[Specialisme Oms].&[$s]"
GetReportInformat -RS $RS -report $report -params $params -format "WORD" -saveas $saveas
Quando eseguo questo script, ottengo questo errore:
Exception calling "Render" with "7" argument(s): "System.Web.Services.Protocols.SoapException: This report requires a
default or user-defined value for the report parameter 'HoofdspecialismeSpecialismeOms'. To run or subscribe to this
report, you must provide a parameter value. ---> Microsoft.ReportingServices.Diagnostics.Utilities.ReportParameterValueNot
SetException: This report requires a default or user-defined value for the report parameter
'HoofdspecialismeSpecialismeOms'. To run or subscribe to this report, you must provide a parameter value.
FACCIO chiaramente fornire un valore per 'HoofdspecialismeSpecialismeOms'; In precedenza ho notato che questo errore viene generato anche quando il parametro non è nel formato previsto. Questo formato, dal momento che il filtro del report si basa su una gerarchia in un cubo SSAS, ha il seguente aspetto: [hierarchy].[sub-level].&[member]
. Ho assicurato che [Hoofdspecialisme].[Specialisme Oms].&[$s]
sia il formato corretto da verificandolo nella query che popola il prompt in SSRS. Il report mostra i dati quando viene eseguito tramite SSRS e prende un parametro dal prompt.
Ho notato che questo parametro consente la selezione multipla. Tuttavia, non credo che ciò porti all'errore, perché ciò vale anche per AanvragendSpecialismeSpecialismeOms
.
Qualche idea sul perché questo parametro non viene inserito nel rapporto quando si chiama GetReportInformat
?
Non ho lavorato molto con Powershell, ma avete provato senza gli spazi aggiuntivi tra i parametri? È spazio delimitato. –
@HannoverFist Ho appena provato a eseguire lo script senza gli spazi e le schede aggiuntivi tra i parametri '-name' e' -val', ma senza fortuna. Ho ancora lo stesso errore. Lo spostamento di 'HoofdspecialismeSpecialismeOms' nell'ordine dei parametri non cambia nulla. – steenbergh
@Matt Hai ragione su '$ q'. Nel mio script, questo è un parametro. Write-Host mi dice che questo viene risolto esattamente come voglio. Ho modificato la domanda per correggere questo valore. Lo script ha una definizione per '$ s', tuttavia, questo è" Urologie ". – steenbergh