$ExecutionContext.InvokeCommand.ExpandString

I have a xml file that holds all the values for a script I’m writing, the below works fine on 2008, but on 2012 it gives me the following error:

Exception calling "ExpandString" with "1" argument(s): "Object reference not set to an instance of an object
At line:1 char:1
+ $ExecutionContext.InvokeCommand.ExpandString(($isecspec.TechSpec.Section | ? {$_ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

The xml entry is (cut off the leading < as the forum treats it as real code):

     
    S
    N
    YO.1.8.1
	<![CDATA[This fixlet checks the permissions for General Users on the following:$($folder.name)The maximum authority granted to general users must be set to the Desired Value for Special Permissions.General Users are users who are not members of the groups listed in the Desired Value for Windows System Privilege Groups.Note: Please refer to the documentation for a detailed matrix of the relationship between Basic and Special Permissions.]]>
    SectionHeading>Protecting Resources - OSRs
    SystemValueParameter>$env:SystemRoot
    Description>OSRs
    RecommendedValue>Read and Execute:::List Folder Contents:::Read
    InitialValue>TBD
    AgreedToValue>^(Read?(Execute|Data|Extended|Attributes|Permissions|And)+?|ExecuteFile|Synchronize|\s|,|-1610612736)+$
   /Section>  
$folders = @{
		$ExecutionContext.InvokeCommand.ExpandString(($isecspec.TechSpec.Section | ? {$_.name -eq "yo.1.8.1"}).systemvalueparameter) = ($isecspec.TechSpec.Section | ? {$_.name -eq "yo.1.8.1"}).name;
}

foreach($folder in $folders.GetEnumerator())
{
	$notes = $ExecutionContext.InvokeCommand.ExpandString(($isecspec.TechSpec.Section | ? {$_.name -eq $folder.value}).notes."#cdata-section")
$perms = ($isecspec.TechSpec.Section | ? {$_.name -eq $folder.value}).agreedtovalue

$notes
$perms
}

I’m not sure why it works on 2008, but not 2012

Well the xml part came out all wrong…wish there was a preview button! and it wont let me edit as well…odd…

Replaced all with -'s

-Section Name="YO.1.8.1"-
    -RunMode-S-/RunMode-
    -Foundation-N-/Foundation-
    -SectionNumber-YO.1.8.1-/SectionNumber-
	-notes--![CDATA[This fixlet checks the permissions for General Users on the following:-br--br--code-$($folder.name)-/code--br--br-The maximum authority granted to general users must be set to the Desired Value for -b-Special Permissions-/b-.-br-General Users are users who are not members of the groups listed in the Desired Value for -b-Windows System Privilege Groups-/b-.-br--br--b-Note:-/b- Please refer to the documentation for a detailed matrix of the relationship between Basic and Special Permissions.]]--/notes-
    -SectionHeading-Protecting Resources - OSRs-/SectionHeading-
    -SystemValueParameter-$env:SystemRoot-/SystemValueParameter-
    -Description-OSRs-/Description-
    -RecommendedValue-Read and Execute:::List Folder Contents:::Read-/RecommendedValue-
    -InitialValue-TBD-/InitialValue-
    -AgreedToValue-^(Read?(Execute|Data|Extended|Attributes|Permissions|And)+?|ExecuteFile|Synchronize|\s|,|-1610612736)+$-/AgreedToValue-
   -/Section-  

<![CDATA[This fixlet checks the permissions for General Users on the following:-br–br–code-$($folder.name)-/code–br–br-The maximum authority granted to general users must be set to the Desired Value for -b-Special Permissions-/b-.-br-General Users are users who are not members of the groups listed in the Desired Value for -b-Windows System Privilege Groups-/b-.-br–br–b-Note:-/b- Please refer to the documentation for a detailed matrix of the relationship between Basic and Special Permissions.]]

The problems seems to be the $($folder.name)

If i just make it $folder.name it runs correctly but shows

System.Collections.DictionaryEntry.name

instead of

c:\Windows

Is there a way to have the value of the variable appear as a string without doing $($folder.name) that will parse correctly on 2012? It’s odd this works on 2008/win7 without issue.

Hi ertuu85,

It’s possible to attach text files to forum posts. Can you do this for the code and the XML, as it’s a bit difficult to work out otherwise?

The xml is located the below URL…i dont see how to attach files…

http://pastebin.com/pWgPVduA

The issues seems to be when I’m doing a $ExecutionContext.InvokeCommand.ExpandString on an xml entry that has $($variable) but i’m not sure how to otherwise display the variable as a string

Resolved it by just changing the value in the XML.

Sorry for this whole mess an thank you Tim!