microsoft / DSCEA

DSC Environment Analyzer (DSCEA) is a simple implementation of PowerShell Desired State Configuration that uses the declarative nature of DSC to scan systems in an environment against a defined reference MOF file and generate compliance reports as to whether systems match the desired configuration.
https://microsoft.github.io/DSCEA
Other
199 stars 41 forks source link

Consider error when a directory is input instead of a MOF #45

Closed zjalexander closed 7 years ago

zjalexander commented 7 years ago

....Please don't ask how I stumbled into this situation, but if you put a directory path into -MofFile instead of a, um, ...file.... You get an error about Access Denied. Please throw a more descriptive error in this case, like "Path must be a file and not a directory".

PS C:\demo> $mofDir = "C:\demo\DSCFromSCMJSON"
PS C:\demo> Start-DSCEAscan -MofFile $mofdir -computername LocalHost

WARNING: Access to the path 'C:\demo\DSCFromSCMJSON' is denied.
rkyttle commented 7 years ago

I feel like adding something like this to the beginning of the Start-DSCEAscan function should accomplish what you are asking

if($MofFile -notlike '*.mof') {
    Write-Error "Please review your MofFile parameter, a full file path to a MOF file was not detected. Ex. -MofFile C:\Users\username\Documents\DSCEA\localhost.mof"
    return
}
else {    
#Begin DSCEA Engine
..................................
}
rkyttle commented 7 years ago

Adding Keith Hitchcock to get his thoughts

rkyttle commented 7 years ago

This should be resolved in the next release