Thanks, AndreasBaumgarten.
PowerShell cmdlets Resolve-Path -Path $variable
Hello,
I did not write this argument and I am a noob when it comes to PowerShell, my predecessor wrote the script and I'm trying to figure out how to resolve the returned result. The issue is that the original server and share path (a Windows Server 2008 R2) has been decommissioned and I have created a new Windows server 2016 with a new share folder.
I'm trying to figure out an If / Else argument that returns an error with unusually fully qualified domain path with doulbe "\".
Variable:
$CertPath = "\servername.domain.com\sharefolder\SSL_Cert.cer"
If/Else:
if (Resolve-Path -Path $CertPath)
{ $CertPath = $(Resolve-Path -Path $CertPath).Path }
else
{ write-statuslog -m "ERROR: Certificate Path cannot be resolve certificate file name: $CertPath" -exit }
Result:
\nERROR: Certificate Path cannot be resolve certificate file name: \\servername.domain.com\sharefolder\SSL_Cert.cer\n
What would be producing the "\" on the FQDN?
Many thanks in advance.
Windows for business | Windows Server | User experience | PowerShell
3 answers
Sort by: Most helpful
-
Anonymous
2020-11-18T03:28:20.28+00:00 Hi,
What is write-statuslog? Please post the code of it if it's a custom function. Or you could just use
Write-Host.$CertPath = "\\servername.domain.com\sharefolder\SSL_Cert.cer" try{ $CertPath = (Resolve-Path -Path $CertPath -ErrorAction Stop).Path } catch{ Write-Host "ERROR: Certificate Path cannot be resolve certificate file name: $CertPath" }Best Regards,
Ian============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. -
Andreas Baumgarten 131.6K Reputation points MVP Volunteer Moderator2020-11-17T19:26:35.157+00:00 Maybe this is helpful for you.
$CertPath = "\\localhost\Testdata\SSL_Cert.cer" if (Test-Path -Path $certpath) { Write-Output "Here it is: $CertPath" } else { Write-Output "Certificate Path cannot be resolve certificate file name: $CertPath" }In both cases the variable "$certpath" contains the full path "\localhost\Testdata\SSL_Cert.cer".
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten