Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Powershell和Visio获取错误_Powershell_Automation_Visio - Fatal编程技术网

使用Powershell和Visio获取错误

使用Powershell和Visio获取错误,powershell,automation,visio,Powershell,Automation,Visio,您好,我正在尝试使用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”) +~~~~~~~~~~~~~~~~~~~~~~~~

您好,我正在尝试使用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”)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+类别信息:无效操作:(:)[],运行时异常
+FullyQualifiedErrorId:InvokeMethodOnFull

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)"

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

页面不是的属性。您需要使用以下属性从集合中获取PC主机:

$pc = $ComputerStencil.Masters.Item("PC")