I need to use powershell to draw visio, but I dont know how powershell can draw containers.
This is the article
https://powershellstation.com/2016/04/18/powershell-and-visio-part-6-containers/
that I have referenced and followed, but it seems $master has not been declared somewhere so it is failing.
I wonder if anyone has any instructions for this problem.
This is my code
$Visio=New-Object -ComObject Visio.Application
$doc=$Visio.Documents.Add(‘’)
$Page=$Visio.ActivePage
$stencilPath=$Visio.GetBuiltInStencilFile(2,0)
$stencil=$Visio.Documents.OpenEx($stencilPath,64)
$page=$Visio.ActivePage
$container=$page.Drop($master,5,5)
$rec=$page.DrawRectangle(2,3,5,6)
$container.ContainerProperties.AddMember($rec,1)
This is the error
You cannot call a method on a null-valued expression.
At line:7 char:1
+ $container.ContainerProperties.AddMember($rec,1)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I appreciate everyone's help.
This is the code to draw container
$stencilPath=$viso.GetBuiltInStencilFile(2,0)
$stencil=$viso.Documents.OpenEx($stencilPath,64)
$Master=$stencil.Masters('Classic')
$Page.Drop($Master,11)
Related
I have win10 Pro and Powershell 5.1
On the other hand VSC(1.54.1) with the powershell extention (ms-vscode-powershell, v2021.2.2).
The command
$day = $day.ToLower()
on the Powershell prompt works fine
But in VSC it says:
+ $dayName = $dayName.ToLower()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
MethodNotFound???
Any help?
Thanks
$dayName.ToString().ToLower() should do what you expect here (according to your comment).
.ToLower() is a string method and you are trying to use it on System.DayOfWeek, which doesn't have that method.
In order to keep track of your variables and just what they are, running $myVariable.GetType().FullName can be very handy - I use it all the time.
In your example, running
$day.GetType().FullName
$dayName.GetType().FullName
would probably result in something like
PS C:\> $day.GetType().FullName
System.String
PS C:\> $dayName.GetType().FullName
System.DayOfWeek
I've been trying to turn OFF the syntax high lighting but using examples here all I get are errors:
Set-PSReadLineOption : A parameter cannot be found that matches parameter name 'TokenKind'.
At line:1 char:22
+ Set-PSReadlineOption -TokenKind Comment -ForegroundColor $Host.UI.Raw ...
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-PSReadLineOption], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.SetPSReadLineOption
Since I don't have what it takes to comment I have to ask a NEW question..
The syntax changed in a recent update. The old syntax will now give you a error message. So now you have to use this:
Set-PSReadLineOption -Colors #{None='black';Comment='black';Keyword='black';String='black';Operator='black';Variable='black';Command='black';Parameter='black';Type='black';Number='black';Member='black'}
Attribution: #Triplee
I have a 3rd party API that I want to use in a PowerShell script. I can instantiate the objects and access properties and non-overloaded methods, but every call to an overloaded method fails with Cannot find an overload for "<method>" and the argument count: "<count>".
The API works fine when called from C#.
Example (here $doc0 contains an instance of an object from the API and Value is the method I want to call):
PS C:\> $doc0.Value.OverloadDefinitions
System.Object IPSFNetDataItem.Value(int fieldIndex)
System.Object IPSFNetDataItem.Value(string field)
PS C:\> $doc0.FieldName(0) #Non-overloaded methods are ok.
ID
PS C:\> $doc0.Value([int]0) #overloaded methods fail
Cannot find an overload for "value" and the argument count: "1".
At line:1 char:1
+ $doc0.Value([int]0) #overloaded methods fail
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
PS C:\> $doc0.Value([string]"why?") #overloaded methods fail
Cannot find an overload for "value" and the argument count: "1".
At line:1 char:1
+ $doc0.Value([string]"why?") #overloaded methods fail
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
I have looked at other similar questions (e.g. here and here) but these solutions do not work in this case - there is surely no room for ambiguity in this very simple case and as the output from OverloadDefinitions shows, I am not trying to do anything that is not supported but the API.
I assume that PowerShell isn't usually this bad at resolving method calls; any ideas why this might be failing?
I created a PowerShell automation script and I gave it to my friend when he run it, it said
Method invocation failed because [mshtml.HTMLBodyClass] does not contain a method
named 'getElementsByClassName'.
At C:\Users\עמית\Documents\asaf.ps1:22 char:3
+ $a=$docs.body.getElementsByClassName("FadeOut-Scroll")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
why is that happened?
We both have IE11, .net 4.5, Visual studio, but I have that function and he not.
And it looks like here in his computer the IE console have the function:
but PowerShell does not:
How to update PowerShell?
Found after alot of time:
the missing want microsoft core xml
Can anyone please suggest me what is wrong - I am calling second script from first so that
I can run the compare in background or parallel, due to bug in IDM software I need to
execute loop two times.
I need to call 5 scripts from my main script ( frist script) so that all five scripts run
parallelly.
First Script -
==================================================
Error message
Attribute cannot be added because it would cause the variable sbtFile with value C to become invalid.
+ CategoryInfo : MetadataError: (:) [Start-Job], ValidationMetadataException
+ FullyQualifiedErrorId : ValidateSetFailure,Microsoft.PowerShell.Commands.StartJobCommand
The command cannot find the job because the CompareCtrlMasterCtrlModelESS name was not found. Verify the value of the Name parameter, and then try the comman
d again.
+ CategoryInfo : ObjectNotFound: (CompareCtrlMasterCtrlModelESS:String) [Wait-Job], PSArgumentException
+ FullyQualifiedErrorId : JobWithSpecifiedNameNotFound,Microsoft.PowerShell.Commands.WaitJobCommand
The command cannot find the job because the CompareCtrlMasterCtrlModelESS name was not found. Verify the value of the Name parameter, and then try the comman
d again.
+ CategoryInfo : ObjectNotFound: (CompareCtrlMasterCtrlModelESS:String) [Receive-Job], PSArgumentException
+ FullyQualifiedErrorId : JobWithSpecifiedNameNotFound,Microsoft.PowerShell.Commands.ReceiveJobCommand
Regards
Naveen
You run Start-Job -Name "CompareCtrlMasterCtrlModelESS" in a loop, so you try to create multiple jobs with the same name. Try Start-Job -Name "CompareCtrlMasterCtrlModelESS$i" (with ordinal suffix).