The property 'InnerText' cannot be found on this object. Verify that the property exists and can be set

Trying to create my first toast script on windows 11 by I keep on getting property cannot be accessed but when I get do get-member the property is in there as string InnertText{get; set;}

$LogFile = "C:\Users\nonyabusiness\Documents\WindowsPowerShell\ToastScript.txt"
Start-Transcript -Path $LogFile -Append
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$Template = [Windows.UI.Notifications.ToastTemplateType]::ToastText02
$ToastContent = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($Template)
$TextElements = $ToastContent.GetElementsByTagName("text")
$TextElements[0] | Get-Member
$TextElements[0].InnerText = "Title of the toast notification"
$TextElements[1].InnerText = "Body of the toast notification"
$TextElements
$Toast = [Windows.UI.Notifications.ToastNotification]::new($ToastContent)
$Notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("PowerShell")
$Notifier.Show($Toast)
Stop-Transcript

Get-Member print out:
Name MemberType Definition


AppendChild Method Windows.Data.Xml.Dom.IXmlNode AppendChild(Windows.Data.Xml.Dom.IXmlNode newChild), Windows.Data.Xml.Dom.IXmlNode IXmlNode.AppendChild(Windows…
CloneNode Method Windows.Data.Xml.Dom.IXmlNode CloneNode(bool deep), Windows.Data.Xml.Dom.IXmlNode IXmlNode.CloneNode(bool deep)
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
Equals Method bool Equals(System.Object obj)
GetAttribute Method string GetAttribute(string attributeName)
GetAttributeNode Method Windows.Data.Xml.Dom.XmlAttribute GetAttributeNode(string attributeName)
GetAttributeNodeNS Method Windows.Data.Xml.Dom.XmlAttribute GetAttributeNodeNS(System.Object namespaceUri, string localName)
GetAttributeNS Method string GetAttributeNS(System.Object namespaceUri, string localName)
GetElementsByTagName Method Windows.Data.Xml.Dom.XmlNodeList GetElementsByTagName(string tagName)
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetType Method type GetType()
GetXml Method string GetXml(), string IXmlNodeSerializer.GetXml()
HasChildNodes Method bool HasChildNodes(), bool IXmlNode.HasChildNodes()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
InsertBefore Method Windows.Data.Xml.Dom.IXmlNode InsertBefore(Windows.Data.Xml.Dom.IXmlNode newChild, Windows.Data.Xml.Dom.IXmlNode referenceChild), Windows.Dat…
Normalize Method void Normalize(), void IXmlNode.Normalize()
RemoveAttribute Method void RemoveAttribute(string attributeName)
RemoveAttributeNode Method Windows.Data.Xml.Dom.XmlAttribute RemoveAttributeNode(Windows.Data.Xml.Dom.XmlAttribute attributeNode)
RemoveAttributeNS Method void RemoveAttributeNS(System.Object namespaceUri, string localName)
RemoveChild Method Windows.Data.Xml.Dom.IXmlNode RemoveChild(Windows.Data.Xml.Dom.IXmlNode childNode), Windows.Data.Xml.Dom.IXmlNode IXmlNode.RemoveChild(Window…
ReplaceChild Method Windows.Data.Xml.Dom.IXmlNode ReplaceChild(Windows.Data.Xml.Dom.IXmlNode newChild, Windows.Data.Xml.Dom.IXmlNode referenceChild), Windows.Dat…
SelectNodes Method Windows.Data.Xml.Dom.XmlNodeList SelectNodes(string xpath), Windows.Data.Xml.Dom.XmlNodeList IXmlNodeSelector.SelectNodes(string xpath)
SelectNodesNS Method Windows.Data.Xml.Dom.XmlNodeList SelectNodesNS(string xpath, System.Object namespaces), Windows.Data.Xml.Dom.XmlNodeList IXmlNodeSelector.Sel…
SelectSingleNode Method Windows.Data.Xml.Dom.IXmlNode SelectSingleNode(string xpath), Windows.Data.Xml.Dom.IXmlNode IXmlNodeSelector.SelectSingleNode(string xpath)
SelectSingleNodeNS Method Windows.Data.Xml.Dom.IXmlNode SelectSingleNodeNS(string xpath, System.Object namespaces), Windows.Data.Xml.Dom.IXmlNode IXmlNodeSelector.Sele…
SetAttribute Method void SetAttribute(string attributeName, string attributeValue)
SetAttributeNode Method Windows.Data.Xml.Dom.XmlAttribute SetAttributeNode(Windows.Data.Xml.Dom.XmlAttribute newAttribute)
SetAttributeNodeNS Method Windows.Data.Xml.Dom.XmlAttribute SetAttributeNodeNS(Windows.Data.Xml.Dom.XmlAttribute newAttribute)
SetAttributeNS Method void SetAttributeNS(System.Object namespaceUri, string qualifiedName, string value)
ToString Method string ToString()
Attributes Property Windows.Data.Xml.Dom.XmlNamedNodeMap Attributes {get;}
ChildNodes Property Windows.Data.Xml.Dom.XmlNodeList ChildNodes {get;}
FirstChild Property Windows.Data.Xml.Dom.IXmlNode FirstChild {get;}
*InnerText Property string InnerText {get;set;}*
LastChild Property Windows.Data.Xml.Dom.IXmlNode LastChild {get;}
LocalName Property System.Object LocalName {get;}
NamespaceUri Property System.Object NamespaceUri {get;}
NextSibling Property Windows.Data.Xml.Dom.IXmlNode NextSibling {get;}
NodeName Property string NodeName {get;}
NodeType Property Windows.Data.Xml.Dom.NodeType NodeType {get;}
NodeValue Property System.Object NodeValue {get;set;}
OwnerDocument Property Windows.Data.Xml.Dom.XmlDocument OwnerDocument {get;}
ParentNode Property Windows.Data.Xml.Dom.IXmlNode ParentNode {get;}
Prefix Property System.Object Prefix {get;set;}
PreviousSibling Property Windows.Data.Xml.Dom.IXmlNode PreviousSibling {get;}
TagName Property string TagName {get;}

What happens if you change the index’s to 1 and 2 versus 0 and 1?

$TextElements is not an array with items directly accessible by index.
It is an XmlNodeList and has a method named item that allows to access by index

1 Like

Yep that’s what I missed it’s a node list