how to update XML value in powershell constrained mode.


  • Hi Everyone. trying to work with azure automation which seems to run in powershell constrained language mode and just cant get an XML value updated like i can in standard powershell and completely unable to fine any useful examples of XML in that mode or a good list of what the magical 'core types' are.


    <ServiceConfiguration serviceName="someservice" xmlns="" osFamily="5" osVersion="*" schemaVersion="2015-04.2.6">
    <Certificate name="somecert" thumbprint="1111111111111111111111111" thumbprintAlgorithm="sha1" />


    # because azure automation runs in constrained mode
    $ExecutionContext.SessionState.LanguageMode = "ConstrainedLanguage"
    # read file
    [xml]$xml = Get-Content 'c:\temp\example.xml'
    # value from file
    # update value
    $xml.ServiceConfiguration.Certificates.Certificate.thumbprint = '222222222222222222222222222'
    # see its been updated

    Error i keep getting.
      Cannot set property. Property setting is supported only on core types in this language mode.

    Anyone know the secret incantation?

    Monday, November 5, 2018 7:25 PM

All replies

  • You have to use an endpoint that is not constrained.  You cannot override this.  Contact the admin of the Azure instance and have them set up an endpoint that allows your operation.


    Monday, November 5, 2018 9:33 PM
  • Thanks, Extremely upsetting that there is no native way to work with XML in constrained mode but at least I know now.



    Tuesday, November 6, 2018 1:43 PM