question

sigfried-9878 avatar image
0 Votes"
sigfried-9878 asked sigfried-9878 edited

WPF & PowerShell - Exception setting "Name": " is not a valid value for property 'Name'."

Hello, I'm trying to build an ADUC browser by using WPF and PowerShell but I'm stuck at a WPF peculiarity by which its naming convention does not consider spaces inside an element's name. Some OUs in AD have names with at least two words and spaces between them.

windows-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

Spaces are not allowed in other projects too: WPF, Forms. You can replace spaces with underscore, probably like this (in several places):

 $itemName = $item.Name.Trim().Replace( " ", "_" )

Also make sure that the name contains only letters, digits, and underscore, and starts with letter or underscore.

Maybe you can also leave the Name of treeview item unassigned.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sigfried-9878 avatar image
0 Votes"
sigfried-9878 answered

or if anybody knows of a sample of WPF/PowerShell please let me know. I can't use C# as per requirements I have for the project.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sigfried-9878 avatar image
0 Votes"
sigfried-9878 answered

Many thanks! As said I already did the trim to no avail. What did the trick was actually to leave the $item name unassigned!

Cheers man!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.