Search code examples
powershellazureagentdsc

Azure DSC VM Extension: Why does $Home directory change?


Environment: PowerShell Version: 5, Windows Server 2016

My DSC creates a Hello World file in the directory:

$Home\Desktop

Which I expected to map to C:\Users\<username>\Desktop. And invoking $home.desktop on the remote VM's PowerShell will indeed return the Desktop directory. But when the DSC itself is executed, the file is instead created in: C:\Windows\System32\config\systemprofile\Desktop.

Below is a copy of the DSC:

Configuration HelloWorldConfig 
{
    Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
       Node localhost 
       {
              File TestFile {
                     Ensure = "Present"
                     DestinationPath = "$Home\Desktop\HelloWorld.txt"
                     Contents = "Hello World!"
              }

       }
}

Any idea why this is happening? Perhaps the Azure VM Agent is its own user and therefore it's $home directory is not in C:\Users, but is rather C:\Windows\System32\config\systemprofile?


Solution

  • The Azure DSC Extension is run by the Azure VM Agent which is running as local system and C:\Windows\System32\config\systemprofile\Desktop is local system's desktop.