参数没有传递给函数

时间:2016-02-29 15:54:12

标签: powershell

我创建了一个PSObject,我想将属性传递给另一个函数,然后输出结果,但它没有传递属性。

在下面的代码中,$VMHostObject.Name函数在Enter-CellData函数中显示为空白,但数据存在于PSObject中。

`Enter-CellData -WorkSheet $ws1 -CellRow $row -CellColumn $Column -Data $VMHostObject.Name`

$VMHostObject = New-Object -TypeName PSObject -Property @{ "Name" = $h.Name "ID" = $h.Id "HypervisiorName" = $view.Config.Product.Name "HypervisiorVersion" = $view.Config.Product.Version "HypervisiorBuild" = $view.Config.Product.Build "Make" = $view.Hardware.SystemInfo.Vendor "Model" = $view.Hardware.SystemInfo.Model "CPUSocketCount" = $view.Hardware.CPUInfo.numCPUPackages "CPUCoreCount" = $view.Hardware.CPUInfo.numCPUCores "LogicalCPUCount" = $view.Hardware.CPUInfo.numCPUThreads "CPYType" = $view.Hardware.CpuPkg.Discription "Memory" = [math]::Round([math]::Round($h.MemoryTotalGB, 2), 2) "Nics100MB" = $100mbNIC "Nics1GB" = $1GBNIC "Nics10GB" = $10GBNIC "NicsOther" = $otherNIC "DatacenterName" = $DataCenter "ClusterName" = $Cluster }

function Enter-CellData { [CmdLetBinding()] param ( [parameter(Mandatory = $true)] [string]$WorkSheet, [parameter(Mandatory = $true)] [int]$CellRow, [parameter(Mandatory = $true)] [int]$CellColumn, [parameter(Mandatory = $true)] [string]$Data )

$WorkSheet.Cells.Item($CellRow, $CellColumn) = $Data
$script:Column++

}

1 个答案:

答案 0 :(得分:0)

我已经在enter-celldata函数中找到了它我有错误的数据类型我现在输入了正确的数据类型

param ( [parameter(Mandatory = $true)] [Object]$WorkSheet, [parameter(Mandatory = $true)] [int]$CellRow, [parameter(Mandatory = $true)] [int]$CellColumn, [parameter(Mandatory = $true)] [PsObject]$Data )