Error occurs just in normal prompt, not ISE - powershell

I was confronted with the following error:
Add-Type : Die Datei oder Assembly "file://\\myuncpath\my.dll" oder eine Abhängigkeit
davon wurde nicht gefunden. Der Vorgang wird nicht unterstützt. (Ausnahme von HRESULT: 0x80131515)
In Zeile:1 Zeichen:1
+ Add-Type -Path "\\myuncpath\my.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
Sorry for it being German but I guess sole the stack trace will help out as well.
And fixed it by enabling loadFromRemoteSources. However this just fixes it for the Powershell ISE not for the typical command prompt that starts when I use right click -> "execute Powershell script".
Does the config not apply to the normal prompt?
Error in English:
Add-Type : Could not load file or assembly 'file://\\myuncpath\my.dl'
or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1 + Add-Type -Path "\\myuncpath\my.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.Ad‌​dTypeCommand

Related

Having issues in connecting exchange online through PowerShell script. Error shows below

Error being received when trying to connect:
New-ExoPSSession : One or more errors occurred.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.5\netFramework\ExchangeOnlineManagement.psm1:475 char:30
+ ... PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AggregateException
+ FullyQualifiedErrorId : System.AggregateException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession

Remote procedure call fails on OneNote.Application.CloseNotebook

Trying to end a OneNote Notebook using Powershell, to later open it under a new path, I get the below exception :
Ausnahme beim Aufrufen von "CloseNotebook" mit 1 Argument(en): "Der
Remoteprozeduraufruf ist fehlgeschlagen. (Ausnahme von HRESULT: 0x800706BE)"
In Zeile:1 Zeichen:1
+ $OneNote.CloseNotebook("{434555E5-54FC-4B61-98FB-158DFBB34B9F}{1}{B0} ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : COMException
Which roughly translates to:
Exception calling "CloseNotebook" with 1 Argument(s): "The remote procedure call failed". (Exception HRESULT: 0x800706BE)
This is the script I used to accomplish the task:
$OneNote = New-Object -ComObject OneNote.Application
[xml]$Hierarchy = ""
$OneNote.GetHierarchy("",[Microsoft.Office.InterOp.OneNote.HierarchyScope]::hspages,[ref]$Hierarchy)
$ID = ($Hierarchy.Notebooks.Notebook |Where-Object {$_.path -like "C:\temp\Test"}).ID
$ID
{434555E5-54FC-4B61-98FB-158DFBB34B9F}{1}{B0}
$OneNote.CloseNotebook($ID)

PowerShell strange execution error

I've created sample cmdlet as a file.ps1 with logic to check my new inbox emails iterative on required time. But when OS Task scheduler (Windows 7) executed it I get these errors:
The interface is unknown. (Exception from HRESULT: 0x800706B5)At
C:\SCRIPTS\my-userAgent.ps1:7 char:7
+ while($ie.busy -eq $true)
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
Method invocation failed because [System.__ComObject] does not contain a
method named 'Navigate'.At C:\SCRIPTS\my-userAgent.ps1:18 char:2
+ $ie.Navigate($url)
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Navigate:String) [], RuntimeE
xception
+ FullyQualifiedErrorId : MethodNotFound
As far as I understand that they are caused by my COM_obj, But why when I execute the same script from PowerShell_ISE it passes and works without errors!?! I've tried to resolve it by:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
hoping that is user_privileges related, but no success so far.
Any help will be appreciated.

MethodArgumentConversionInvalidCastArgument after version update

After updating NuGet to version 2.8.50313.31, opening the Package Manager Console displays a number of errors.
Is this a known issue with that (now current) version? Is there a fix/work-around?
If there is no fix, how does one revert to the previous version of NuGet?
New-Object : Could not load file or assembly
'System.Management.Automation, Ver sion=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its d ependencies. The
system cannot find the file specified. At
E:\dev\myProject\packages\MvcScaffolding.1.0.6\tools\registerWithMvcTooling.ps1
:143 char:27
+ $newProvider = New-Object <<<< $powerShellScaffolderProviderType($mvcSca ffoldingProvider)
+ CategoryInfo : NotSpecified: (:) [New-Object], FileNotFoundExce ption
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerS
hell.Commands.NewObjectCommand Cannot convert argument "0", with
value: "Microsoft.VisualStudio.Web.Mvc.Scaffo
lding.PowerShell.PowerShellScaffolderProvider", for "Add" to type
"Microsoft.Vi
sualStudio.Web.Mvc.Extensibility.Scaffolding.ScaffolderProvider":
"Cannot conve rt the
"Microsoft.VisualStudio.Web.Mvc.Scaffolding.PowerShell.PowerShellScaffol
derProvider" value of type
"Microsoft.VisualStudio.Web.Mvc.Scaffolding.PowerShe
ll.PowerShellScaffolderProvider" to type
"Microsoft.VisualStudio.Web.Mvc.Extens
ibility.Scaffolding.ScaffolderProvider"." At
E:\dev\myProject\packages\MvcScaffolding.1.0.6\tools\registerWithMvcTooling.ps1
:144 char:19
+ $allProviders.Add <<<< ($newProvider) | Out-Null
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument PM> New-Object : Could
not load file or assembly 'System.Management.Automation, Ver
sion=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one
of its d ependencies. The system cannot find the file specified. At
E:\dev\myProject\packages\MvcScaffolding.1.0.6\tools\registerWithMvcTooling.ps1
:143 char:27
+ $newProvider = New-Object <<<< $powerShellScaffolderProviderType($mvcSca ffoldingProvider)
+ CategoryInfo : NotSpecified: (:) [New-Object], FileNotFoundExce ption
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerS
hell.Commands.NewObjectCommand Cannot convert argument "0", with
value: "Microsoft.VisualStudio.Web.Mvc.Scaffo
lding.PowerShell.PowerShellScaffolderProvider", for "Add" to type
"Microsoft.Vi
sualStudio.Web.Mvc.Extensibility.Scaffolding.ScaffolderProvider":
"Cannot conve rt the
"Microsoft.VisualStudio.Web.Mvc.Scaffolding.PowerShell.PowerShellScaffol
derProvider" value of type
"Microsoft.VisualStudio.Web.Mvc.Scaffolding.PowerShe
ll.PowerShellScaffolderProvider" to type
"Microsoft.VisualStudio.Web.Mvc.Extens
ibility.Scaffolding.ScaffolderProvider"." At
E:\dev\myProject\packages\MvcScaffolding.1.0.6\tools\registerWithMvcTooling.ps1
:144 char:19
+ $allProviders.Add <<<< ($newProvider) | Out-Null
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument New-Object : Could not
load file or assembly 'System.Management.Automation, Ver sion=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its d
ependencies. The system cannot find the file specified. At
E:\dev\myProject\packages\MvcScaffolding.1.0.6\tools\registerWithMvcTooling.ps1
:143 char:27
+ $newProvider = New-Object <<<< $powerShellScaffolderProviderType($mvcSca ffoldingProvider)
+ CategoryInfo : NotSpecified: (:) [New-Object], FileNotFoundExce ption
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerS
hell.Commands.NewObjectCommand Cannot convert argument "0", with
value: "Microsoft.VisualStudio.Web.Mvc.Scaffo
lding.PowerShell.PowerShellScaffolderProvider", for "Add" to type
"Microsoft.Vi
sualStudio.Web.Mvc.Extensibility.Scaffolding.ScaffolderProvider":
"Cannot conve rt the
"Microsoft.VisualStudio.Web.Mvc.Scaffolding.PowerShell.PowerShellScaffol
derProvider" value of type
"Microsoft.VisualStudio.Web.Mvc.Scaffolding.PowerShe
ll.PowerShellScaffolderProvider" to type
"Microsoft.VisualStudio.Web.Mvc.Extens
ibility.Scaffolding.ScaffolderProvider"." At
E:\dev\myProject\packages\MvcScaffolding.1.0.6\tools\registerWithMvcTooling.ps1
:144 char:19
+ $allProviders.Add <<<< ($newProvider) | Out-Null
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
It turns out that MvcScaffolding.1.0.6 is no longer referenced by any project in the solution.
Removing it from the NuGet command line
Uninstall-Package MvcScaffolding
resolved the issue.
There is currently version 1.0.9 of MvcScaffolding. The issue may be resolved in that version. However, since I no longer reference that package, I did not test that.

Powershell named parameters error

I'm tring to do the following:
$Feature = "OWAEnabled"
Set-CasMailbox Admin -$($Feature) $False
But i get each time this error:
Set-CASMailbox : Es wurde kein Positionsparameter gefunden, der das Argument "-OWAEnabled:True" akzeptiert.
In Zeile:1 Zeichen:2
+ set-casmailbox Administrator -$($Feature):$True
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-CASMailbox], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Exchange.Management.RecipientTasks.SetCASMailbox
Can someone help me?
Thanks a lot
This will work, though not the prettiest:
$Feature = "OWAEnabled"
$c = "Set-CasMailbox Admin -$($Feature):`$False"
Invoke-Expression $c