2

嗨,我正在尝试使用 powershell 生成 visio drwaings,但出现以下错误;

PS C:\Users\XXXX\Desktop\Scripts> C:\Users\XXXX\Desktop\Scripts\tempv.ps1 您不能在空值表达式上调用方法。在C:\Users\XXXX\Desktop\Scripts\tempv.ps1:14 char:1 + $pc = $ComputerStencil.Masters.Page("PC") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

PS C:\Users\XXXX\Desktop\Scripts>

请告诉我这里有什么问题;我尝试了很多,但没有弄错;

$application = New-Object -ComObject Visio.Application
#$application.visible = $false
$documents = $application.Documents
$document = $documents.Add("Basic Network Diagram.vst")
$pages = $application.ActiveDocument.Pages
$page = $pages.Item(1)

$NetworkStencil = $documents.Add("periph_m.vss")
$ComputerStencil = $documents.Add("Computers and Monitors.vss")
$ConnectorStencil = $documents.Add("Connectors.vss")
$pcinfo = Get-ComputerSystem -computer $computer

#***********************WORKS UNTILL HERE**************
#*****ERROR PART***************
$pc = $ComputerStencil.Masters.Page("PC")
$shape1 = $page.Drop($pc, 2.2, 6.8) 
$shape1.Text = "$($pcinfo.DNSHostName)`r`n$($pcinfo.Domain)"
4

2 回答 2

1

Page 不是Masters的财产。您需要使用Item属性从集合中获取 PC Master:

$pc = $ComputerStencil.Masters.Item("PC")
于 2012-08-03T00:02:21.290 回答
0

要么$ComputerStencil要么$ComputerStencil.Masters$null。您可以只点源脚本并在命令行中查看变量和对象(有时比在 ISE 中使用调试器更容易)。

于 2012-08-02T21:16:18.920 回答