How to resolve - Relative path is not supported in PowerShell DSC?


“Relative path is not supported” error generally occurs with the PowerShell DSC when we download a file from online or Website and we use “File” DscResource for that.

In the below example, we are downloading the PowerShell 7.1.4 version from GitHub using DSC to the local computer and we get the error below.

Example

Configuration FileCopy{
   Node LocalHost{

      File CopyFromBlob{
         SourcePath = "https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/PowerShell-7.1.4-win-x86.msi"
         DestinationPath = "C:\Temp\"
         Ensure = 'Present'
      }
   }
}
FileCopy -OutputPath C:\Temp\dsc\FileCopy
Start-DscConfiguration -Path C:\Temp\dsc\FileCopy -Wait -Force

Output

Relative path is not supported. The related file/directory is:
https://github.com/PowerShell/PowerShell/releases/download/v7.1.
4/PowerShell-7.1.4-win-x86.msi.
   + CategoryInfo : InvalidArgument: (:) [], CimException
   + FullyQualifiedErrorId : MI RESULT 4
   + PSComputerName : LocalHost

To resolve this error, we can either use the “Script“ DSC resource or we need to download and Install the additional DSC resource “xRemoteFile” to download the file online.

To install the “xRemoteFile” resource use the below command.

Find-DscResource xRemoteFile | Install-Module -Force -Verbose

Once the command is installed, we can use the below configuration.

Configuration FileCopy{

   Import-DscResource -ModuleName xPSDesiredStateConfiguration
   Node LocalHost{
      xRemoteFile FileDownload{
         URI = "https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/PowerShell-7.1.4-win-x86.msi"
         DestinationPath = "C:\Temp\PowerShell-7.1.4-win-x86.msi"
      }
   }
}
FileCopy -OutputPath C:\Temp\dsc\FileCopy
Start-DscConfiguration -Path C:\Temp\dsc\FileCopy -Wait -Force

You can also use the inbuilt Script DSC resource as shown below.

Configuration FileCopy{
   Node LocalHost{
      Script DownloadFile{
         GetScript = {""}
         SetScript = {
            Invoke-WebRequest -
            Uri "https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/PowerShell-7.1.4-win-x86.msi"
               -OutFile C:\Temp\PowerShell-7.1.4-win-x86.msi
         }
         TestScript = {
            If(!(Test-Path C:\Temp\PowerShell-7.1.4-win-x86.msi)){return $false}
            else{return $true}
         }
      }
   }
}

Updated on: 01-Sep-2021

448 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements