dsccommunity / StorageDsc

DSC resource module is used to manage storage on Windows Servers.
https://dsccommunity.org
MIT License
66 stars 51 forks source link

Dev Drive DSC error message when not run as admin #284

Open AdamBraden opened 6 months ago

AdamBraden commented 6 months ago

Problem description

Lost a little time running the DSC on a new vm, only to realize I forgot to run it under an admin command prompt. The error message is misleading and that's why took a bit to figure it out.

Verbose logs

Error: 
The configuration unit failed while attempting to apply the desired state.
There is no unallocated space available to create the Dev Drive volume. We found no partitions that could be resized to create '50Gb' of unallocated space.
<See the log file for additional details>
Some of the configuration was not applied successfully

DSC configuration

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2

###############################################################################
# Dev Drive - configure a 50GB dev drive                                      #
###############################################################################

properties:
  configurationVersion: 0.2.0
  resources:
   - resource: Disk
     id: DevDrive1
     directives:
       description: 'Format a new Dev Drive volume onto Disk 0'
       module: StorageDsc
       allowPrerelease: true
     settings:
       DiskId: '0'
       DiskIdType: 'Number'
       DriveLetter: 'E'
       FSLabel: 'DevDrive1'
       DevDrive: true
       AllowDestructive: true
       FSFormat: 'ReFS'
       Size: '50Gb'

Suggested solution

An error message that notifies the user to run the command as an administrator. I'm not sure if there are other patterns to follow, but something along the lines of:

Error: Administrator privileges required

Operating system the target node is running

OsName               : Microsoft Windows 11 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 22621.1.amd64fre.ni_release.220506-1250
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell version and build the target node is running

Name                           Value
----                           -----
PSVersion                      7.3.11
PSEdition                      Core
GitCommitId                    7.3.11
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

StorageDsc version

Name       Version Path
----       ------- ----
StorageDsc 6.0.0   C:\Users\adambr\OneDrive - Microsoft\Documents\PowerShell\Modules\StorageDsc\6.0.0\StorageDsc.psd1
bbonaby commented 6 months ago

Yes we'll need to add a check to confirm if we're running the DSC resource as Admin and also mention in the wiki that it is needed as well.

FYI for those who don't know the config file above is a WinGet DSC config file see: https://learn.microsoft.com/en-us/windows/package-manager/configuration/create#example-winget-configuration-file

PlagueHO commented 5 months ago

We should add this to the README.md in here as well.