Forum Discussion
What is the filename referenced in this script?
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"
}
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:- Application.FileSaveAs method (Project) | Microsoft Learn
- ms office - Microsoft Project Export Map, copying the map itself - Stack Overflow
Cheers,
Lain
- LainRobertsonSilver Contributor
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:- Application.FileSaveAs method (Project) | Microsoft Learn
- ms office - Microsoft Project Export Map, copying the map itself - Stack Overflow
Cheers,
Lain
- KhibbyCopper ContributorThank 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!
- KhibbyCopper ContributorSo 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?
- LainRobertsonSilver Contributor
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:
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