none
how to update XML value in powershell constrained mode.

    Question

  • 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.

    XML

    <ServiceConfiguration serviceName="someservice" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="5" osVersion="*" schemaVersion="2015-04.2.6">
    <Certificates>
    <Certificate name="somecert" thumbprint="1111111111111111111111111" thumbprintAlgorithm="sha1" />
    </Certificates>
    </ServiceConfiguration>

    Powershell

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

    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.

    thanks

    tim

    Tuesday, November 6, 2018 1:43 PM