嗨,我正在尝试使用 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)"