SOLVED

What is the filename referenced in this script?

Copper Contributor

The guy that wrote this script is no longer with the company.  When I run it I get a message from Project, "The map with the specified name does not exist.  Verify the name is correct, and try again."  I have checked permissions and disabled antivirus COM addin but cannot get past this message.  Then a users tells me there may have been some excel files deleted.  So I'm looking to recreate the excel files and test the script again.  However, I cannot figure out what the filename should be from the script.  Can someone help me decipher?  

#Set File Paths
$ProjectFilesSourcePath = "\\company\shares\dept02\TSubConstruction\workplan\"
#$SavePath = "\\company\shares\Group3\Transmission PMO\Power BI Supplements\Subs Crew Path Files\"
$SavePath = "\\company\shares\Group3\Transmission PMO\Power BI Supplements\Subs Crew Path Files\"

#Remove Previous Project Export Files
$Files = Get-ChildItem Microsoft.PowerShell.Core\FileSystem::$SavePath

$Files | foreach{
$FilePath = $_.FullName
Remove-Item Microsoft.PowerShell.Core\FileSystem::$FilePath -Force
}

#Get List of Subs Construction Project Files
$ProjectFiles = Get-ChildItem Microsoft.PowerShell.Core\FileSystem::$ProjectFilesSourcePath

#Clear Errors
$Error.Clear()

#Create List to hold Errors
$ErrorList = @()

#Create MS Project Object
$Project = New-Object -ComObject msproject.application

#Export Each Project File
$ProjectFiles | foreach{

#if ($_.Name -eq "RD Projects Schedule.mpp"){

try{
$Name = $_.BaseName
$ProjectSourceFileName = Join-Path $ProjectFilesSourcePath $_.Name
$ExportFileName = Join-Path $SavePath $_.BaseName

#Open File
$Project.FileOpenEx($ProjectSourceFileName, "True") |Out-Null

#Convert to Excel and Save
$Project.FileSaveAs($ExportFileName, "pjXLSX", [Type]::Missing, [Type]::Missing, [Type]::Missing, [Type]::Missing, [Type]::Missing, [Type]::Missing, [Type]::Missing, [Type]::Missing, "BI Export") |Out-Null

#Close Project File
$Project.FileCloseEx(0) |Out-Null
}

catch{
#Write-Error "Exception Message: $($_.Exception.Message)"

#Close Project File
$Project.FileCloseEx(0) |Out-Null

#Collect List of Errored Files
$ErrorList += $Name
}

#}

}

#Close MS Project
$Project.FileExit(0) |Out-Null

#Dispose of Object
[Runtime.InteropServices.Marshal]::ReleaseComObject($Project) |Out-Null
[GC]::Collect()
[GC]::WaitForPendingFinalizers()

#Output Export Results
if($Error)
{
"Error Count: " + $ErrorList.Length
$ErrorList
Write-Error "Export Failed" -ErrorAction Stop
}
else
{
"Export Completed Successfully"
}

6 Replies
best response confirmed by Khibby (Copper Contributor)
Solution

@Khibby 

 

This isn't a PowerShell issue but rather an issue using the msproject.application class.

 

My best guess - given the lack of specificity in the error - is that the error is coming from the 

$Project.FileSaveAs() call on line 40, and specifically relates to the map parameter value of "BI Export".
 
Here's some references:
 

 

Cheers,

Lain

Thank you for the reference material! I believe you are right about the map paramenter for "BI Export". I'm new to PS for data manipulation. Thank you again!
So when I run it and Project send the error: "the map with the specified name does not exist" it is referencing "BI Export". What is "BI Export"? Is it an excel file?

@Khibby 

 

I'm not sure what a "map" is in Project.

 

Perhaps try researching it on learn.microsoft.com or even asking in one of the Office TechCommunity forums?

 

Hopefully someone else here might know, but it's worth asking around in forums more closely related to Project.

 

I'd imagine that even if you tried opening and possibly then "saving as" the relevant Project file manually, you'll get the same error from Project itself.

 

Cheers,

Lain

@Khibby 

 

I had a rummage around in Project and found the following area, which I got to via Fil > Info > Organizer, but I don't know if this is the only (or even the right) way:

 

LainRobertson_0-1702003963710.png

 

This might be where the "BI Export" reference fits in.

 

But now I really am at the end of the line on this one.

 

Cheers,

Lain

I have been studying this online. I believe it is a template that I need to build out and copy to the Global.MPT. I'm still researching, but I will post a the solution when I find it. Thank you for guiding me through this! I appreciate it!
1 best response

Accepted Solutions
best response confirmed by Khibby (Copper Contributor)
Solution

@Khibby 

 

This isn't a PowerShell issue but rather an issue using the msproject.application class.

 

My best guess - given the lack of specificity in the error - is that the error is coming from the 

$Project.FileSaveAs() call on line 40, and specifically relates to the map parameter value of "BI Export".
 
Here's some references:
 

 

Cheers,

Lain

View solution in original post