I use the below logic in my Powershell script to map a network drive to read the installation logs and based on the Installation status, it would validate if the installation was successful and I unmap the drive later on.
However I'm seeing errors recently. I'm not sure what is that I'm missing in my script.
New-PSDrive : The local device name has a remembered connection to another network resource At C:\Windows\TEMP\jenkins3036451124142125854.ps1:31 char:1
+ New-PSDrive -Name M -PSProvider FileSystem -Root "${LogFilePath}" -Cr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (M:PSDriveInfo) [New-PSDrive], Win32Exception
+ FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Com mands.NewPSDriveCommand Set-Location : Cannot find drive. A drive with the name 'M' does not exist. At line:1 char:1
+ Set-Location $MyInvocation.MyCommand.Name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (M:String) [Set-Location], Drive NotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetL ocationCommand Get-ChildItem : Cannot find drive. A drive with the name 'M' does not exist. At C:\Windows\TEMP\jenkins3036451124142125854.ps1:35 char:20
+ ${LatestLogFile} = Get-ChildItem M:\ | Sort CreationTime -Descending ...
+ ~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (M:String) [Get-ChildItem], Driv eNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetC hildItemCommand ---------- latest log file is ----------- Get-Content : Cannot find drive. A drive with the name 'M' does not exist. At C:\Windows\TEMP\jenkins3036451124142125854.ps1:39 char:22
+ $Installer_LogFile = Get-Content -LiteralPath M:\${LatestLogFile}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (M:String) [Get-Content], DriveN otFoundException + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetC ontentCommand
# Logic to read the log file and verify
${LogFilePath} = “\\inv-r4-bvt-21\c$\FhirInstalls\$Source\installer\logs”
$User = "cor\inbuildu"
$PWord = ConvertTo-SecureString -String "******" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
New-PSDrive –Name M –PSProvider FileSystem –Root "${LogFilePath}" -Credential $Credential –Persist -Scope Global
M:
${LatestLogFile} = Get-ChildItem M:\ | Sort CreationTime -Descending | Select -First 1
Write-Output "---------- latest log file is -----------"
Write-Output ${LatestLogFile}
$Installer_LogFile = Get-Content -LiteralPath M:\${LatestLogFile}
$Install_Complete_Message = $Installer_LogFile | %{$_ -match "STEP: Install of FHIR is complete!"}
$Install_Complete_Message_Components = $Installer_LogFile | %{$_ -match "STEP: Install of selected component\(s\) is complete!"}
if (($Install_Complete_Message -contains $true) -or ($Install_Complete_Message_Components -contains $true))
{
Write-Host "Fhir API installed succesfully!"
} else {
Write-Host "Failed to install Fhir API!!"
$LastExitCode = 1
exit $LastExitCode
}
C:
Remove-PSDrive M
if ($RemoteSession){remove-pssession $RemoteSession}