Remote procedure call fails on OneNote.Application.CloseNotebook - powershell

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)

Related

Powershell creating microsoft access database error

I am running the following code in windows powershell:
Function Create-DataBase($Db){
$application = New-Object -ComObject Access.Application
$application.NewCurrentDataBase($Db,10)
$application.CloseCurrentDataBase()
$application.Quit()
} #End Create-DataBase
#$dbname = Read-Host -Prompt 'Input your database name'
# database file location
$Db = 'C:\new.mdb'
If(Test-Path $Db){
Write-Host 'DB already exists' -fore green
}else{
Create-DataBase $Db
}
But getting the following error,
Exception calling "NewCurrentDatabase" with "5" argument(s): "An error
occurred while trying to create the database." At
E:\Mahmood\test2.ps1:3 char:33
+ $application.NewCurrentDataBase <<<< ($Db,10)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Exception calling "CloseCurrentDatabase" with "0" argument(s): "The expression
you entered refers to an object that is closed or doesn't exist." At
E:\Mahmood\test2.ps1:4 char:35
+ $application.CloseCurrentDataBase <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Anyone have any idea what's wrong.

Powershell LDAP FindAll() error

I'm trying to connect to new LDAP server which gives me following error. Old site was working without any problems. Can you help?
$dn = "LDAP://ldap.site.cz:389/ou=People,dc=site,dc=com"
$auth = [System.DirectoryServices.AuthenticationTypes]::Anonymous
$de = New-Object System.DirectoryServices.DirectoryEntry($dn,$null,$null,$auth)
$ds = New-Object System.DirectoryServices.DirectorySearcher($de)
[void]$ds.PropertiesToLoad.Add("uid")
$colResults = $ds.FindAll()
Which gives me...
Exception calling "FindAll" with "0" argument(s): "Unknown error (0x80005000)"
At line:9 char:1
+ $colResults = $ds.FindAll()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : COMException

Error occurs just in normal prompt, not ISE

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

Unable to Cast COM Object of type

Language: Powershell
Usage: Login into Website
Code: (NOTE: Actual values for lines 1., 2., and 4. have not been provided)
$username = "User"
$password = "Password"
$ie = new-object -com "InternetExplorer.Application"
$ie.navigate("URL")
$ie.visible =$true
$doc = $ie.document
$doc.getElementByID("username").value=$username
$doc.getElementByID("password").value=$password
$link = #($doc.getElementsByTagName('A')) | where-object {$_.innerText -eq 'Log In'}
$link.click
Lines 1 thru 6 work perfectly and launch the default browser to the Login Page of the specified URL.
Lines 7 thru 9 produce the following errors:
Line 7:
Exception calling "getElementById" with "1" argument(s): "Unable to cast
COM object of type 'mshtml.HTMLDocumentClass' to interface type
'mshtml.DispHTMLDocument'. This operation failed because the
QueryInterface call on the COM component for the interface with IID
'{3050F55F-98B5-11CF-BB82-00AA00BDCE0B}' failed due to the following
error: No such interface supported (Exception from HRESULT:
0x80004002 (E_NOINTERFACE))."
At line:1 char:20
+ $doc.getElementByID <<<< ("username").value=$username
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Line 8:
Exception calling "getElementById" with "1" argument(s): "Unable to cast
COM object of type 'mshtml.HTMLDocumentClass' to interface type
'mshtml.DispHTMLDocument'. This operation failed because the
QueryInterface call on the COM component for the interface with IID
'{3050F55F-98B5-11CF-BB82-00AA00BDCE0B}' failed due to the following
error: The RPC server is unavailable. (Exception from HRESULT:
0x800706BA)."
At line:1 char:20
+ $doc.getElementByID <<<< ("password")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Line 9:
Exception calling "getElementsByTagName" with "1" argument(s): "Unable to
cast COM object of type 'mshtml.HTMLDocumentClass' to interface type
'mshtml.DispHTMLDocument'. This operation failed because the
QueryInterface call on the COM component for the interface with IID
'{3050F55F-98B5-11CF-BB82-00AA00BDCE0B}' failed due to the following
error: The object invoked has disconnected from its clients. (Exception
from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))."
At line:1 char:36
+ $link = #($doc.getElementsByTagName <<<< ('A')) | where-object
{$_.innerText -eq 'Log In'}
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
I am not sure what this error is telling me and need some suggestions from some Powershell Gurus out there. I could not find anything in the stack that has this issue covered based on the use of Powershell.
Thanks in advance for any help.
What happens if you put sleep before looking into the document?
do { Sleep 1 } while( $ie.Busy -or $ie.ReadyState -ne 4 )
like this
$ie.visible =$true
do{Sleep 1} while( $ie.Busy -or $ie.ReadyState -ne 4 )
$doc = $ie.document

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