我有两个自定义的 powershell 函数,它们的用途如下:
Get-Users | Select LoginName | Get-UserJobStatus -StartDate 2013-02-19 -EndDate 2013-02-21
运行此程序时,我收到来自 Web 服务的错误:
@{LoginName=UserName} not found
这是有道理的,因为传递给 Web 服务函数的用户名应该只是 UserName 而不是 @{LoginName=username}。如何正确格式化?
function Global:Get-BackupJobStatus
{
[cmdletBinding()]
Param(
[Parameter(
Mandatory=$True,
HelpMessage='Specific account name.',
ParameterSetName='LoginName',
ValueFromPipeline=$True
)]
[System.String[]]$LoginName = $null,
[Parameter(
Mandatory=$false,
HelpMessage='Start date for report.'
)]
[System.DateTime]$startDate,
[Parameter(
Mandatory=$false,
HelpMessage='Ending date for report.'
)]
[System.DateTime]$EndDate
)
Begin {
$tempXml = New-Object System.Xml.XmlDocument
Write-Output $StartDate.toString("yyyy-MM-dd")
}
Process{
$tempXml.Load("https://webservicecall/info.do?LoginName="+$LoginName+"&Date="+$startDate.toString("yyyy-MM-dd"))
}
End {
Write-Output $tempXml.Users.User
}
}