Author Posts

December 14, 2015 at 12:52 pm

I am trying to gather the acl for each of our mail-in databases. I have found a way to do so with one database, but for some reason when I try to expand the process to use a loop to grab them all, I end up failing.

The working part goes as follows:
$Notes = New-Object -ComObject Lotus.NotesSession
$Notes.Initialize()
$server = "servername"
$folder = "mail-in"
$database = "filename.nsf"
$NotesDabase = $Notes.GetDatabase($server,"folder\$datbase")
$acl = $notesdatabase.acl
$firstentry = $acl.GetfirstEntry()
While ($firstentry -ne $null)
{
Write-Output $firstentry.name
$nextentry = $$acl.getnextentry($firstentry)
$firstentry = $nextentry
}

It stops working when I try to use a for loop to handle a number of databases. It seems as though the acl property is lost in the process somehow, so that when it looks for it, it comes up with a null value and failes.

$Notes = New-Object -ComObject Lotus.NotesSession
$Notes.Initialize()
$MailServer="caml01/caind/us"
$Folder = "mail-in"
$server = "\\caml01\d$\lotus\domino\data\"
$database = "helpdesk.nsf"
$List = dir "$server\$folder"
$Files = $List | select -property name
Foreach ($F in $Files)
{
$NotesDatabase = $Notes.GetDatabase($mailserver,"$folder\$F")
$Acl = $NotesDatabase.ACL
$FirstEntry = $acl.GetFirstEntry()
}
While ($Firstentry -ne $null)
{
Write-Output $FirstEntry.Name
$NextEntry = $Acl.GetNextEntry($FirstEntry)
$FirstEntry = $Nextentry
}
}

December 14, 2015 at 12:58 pm

You've run into one of the most fun PowerShell gotchas.

$Files = $List | select -property name

$Files is not a list of filenames as this point. It is a collection of objects, each of which has a Name property only. You probably wanted to do this:

$Files = $List | select -expandproperty name

Now, $Files is indeed just a list of strings. Although it could also include folders, since your Get-ChildItem didn't restrict the results to only file objects. Use the -File parameter to do that.

See https://powershell.org/kb/properties-vs-values/ for a deeper explanation. As a debugging note, this happened because $F didn't contain what you thought it did. I'd have added some code to output the contents of my variables, or set a breakpoint inside the loop and manually inspected the contents of the variables, to confirm that they continued what I thought they did.

In your case, "$folder\$F" probably evaluated to something like "folder name\{Selected.System.FileInfo}" or something, which I bet isn't what you thought it would.

Do me a favor, add this:

Foreach ($F in $Files)
{
Write-Output "F contains $F"
$NotesDatabase = $Notes.GetDatabase($mailserver,"$folder\$F")

before making the change I suggested. Then, make the -expandproperty change and run it again. You'll see the difference.

December 14, 2015 at 2:08 pm

Thank you very much, sir. I was thinking it had something to do with item types but I danced around the issue too much and missed the solution.

For any who are curious, the contents of $F before the expand were showing as @{Name=Helpdesk.nsf}.
Afterwards it was helpdesk.nsf