- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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} } } } }
Advertisements
To Continue Learning Please Login
Login with Google