guitarrapc / GraniResource

PowerShell Desired State Configuration Resources for real production workload.
https://www.powershellgallery.com/packages/GraniResource
MIT License
43 stars 8 forks source link

Symbolic link errors on subsequent applys #87

Open ScottGuymer opened 4 years ago

ScottGuymer commented 4 years ago

I am using the symbolic link resource and it applies successfully the first time and creates the link correctly. But on subsequent runs, it fails.

I think its something to do with the test function as it seems to think that the link doesn't exist and tries to re-create it when it already exists.

My DSC config is

    $documents = [Environment]::GetFolderPath("MyDocuments")    
    cSymbolicLink powershellProfileLink {
      Ensure          = "Present"
      SourcePath      = "C:\code\powershell-profile\"
      DestinationPath = "$documents\WindowsPowerShell\"
      DependsOn       = "[cGitRepository]powershellProfile"
    }

the error message is.

VERBOSE: [NLYBSTQVP4NB88O]: LCM:  [ Start  Resource ]  [[cSymbolicLink]powershellProfileLink]
VERBOSE: [NLYBSTQVP4NB88O]: LCM:  [ Start  Test     ]  [[cSymbolicLink]powershellProfileLink]
VERBOSE: [NLYBSTQVP4NB88O]: LCM:  [ End    Test     ]  [[cSymbolicLink]powershellProfileLink]  in 0.0590 seconds.
VERBOSE: [NLYBSTQVP4NB88O]: LCM:  [ Start  Set      ]  [[cSymbolicLink]powershellProfileLink]
VERBOSE: [NLYBSTQVP4NB88O]:                            [[cSymbolicLink]powershellProfileLink] DestinationPath : 'C:\Users\320047825\OneDrive - Philips\Documents\WindowsPowerShell\',  SourcePath :
'C:\code\powershell-profile\', IsDirectory : 'False'
Exception calling "CreateSymLink" with "3" argument(s): "Cannot create a file when that file already exists"
    + CategoryInfo          : NotSpecified: (:) [], CimException
    + FullyQualifiedErrorId : Win32Exception
    + PSComputerName        : localhost

VERBOSE: [NLYBSTQVP4NB88O]: LCM:  [ End    Set      ]  [[cSymbolicLink]powershellProfileLink]  in 0.1390 seconds.
The PowerShell DSC resource '[cSymbolicLink]powershellProfileLink' with SourceInfo 'C:\code\windows-dev-config\devMachineConfig.ps1::85::5::cSymbolicLink' threw one or more non-terminating errors while running
the Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

VERBOSE: [NLYBSTQVP4NB88O]: LCM:  [ End    Set      ]
The SendConfigurationApply function did not succeed.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost

VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 18.029 seconds