Using an index of an array to build a user selection menu - powershell

I'm working on a PowerShell script which sets a variable based on a user selection from an array, but I can't find any approach to realize this.
There is a variable named $org which is filled by a cmdlet with an array of entries looking like this:
My goal is to create a user selection menu which prompts to select one entry of that array writing this selection to a variable which can be used in the ongoing script. The number of entries in that array can vary.
I tried something with switch-operator but no success. I'm completely stumped. :-/
Thank you,
Chris

Related

User input into a script in Powershell GUI

hoping for some help. I've got a dialog box that I want to do a certain action and running into issues getting the user input as a variable in the script. Essentially I want the user to be able to copy down a row in excel (so, for example, copy 4 numbers down a line in row E). I want the user to be able to paste it into the powershell GUI I made, once pasted I want the button to use that user input and put it in to a script I have already made and execute using each of those numbers as a variable and to return the output of the script. I've got the script and button made i'm just not sure what cmdlet or functions I need to do in order to take the user input and place in the script as a variable. Any help is appreciated, thank you!!
I went through Microsoft Docs and tried to find a cmdlet but either I didn't understand it or it didn't seem to work.

Pulling data from and writing back to an Excel spreadsheet in PowerShell

Right, I'm putting a script together to be run post-Windows install to change a few settings, re-name the computer and join a domain. I've got everything working fine but where it currently asks the user to provide a computername (which they will be taking from a spreadsheet) I'd ideally like the script to take the next available name from the file and then write back a value for the adjacent field with a value provided by the user (the end-user's name).
Is this at all possible or am I expecting too much here?
Thanks in advance!
Check out the PowerShell Module https://www.powershellgallery.com/packages/ImportExcel/5.1.1

Copy name of object in variable explorer

I frequently find myself examining deeply nested data in the variable explorer, e.g.:
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray(4)
In order to be descriptive, the variable names are often long. I often want to use some of the data I'm looking at in Matlab expression, composed at the command line. So I end up typing the lengthy series of variable names and indexes. Autocompletion helps, but not much, especially since my variable names share many substrings.
It would be a lifesaver if I could copy into the clipboard the entire expression corresponding to the data being examined in the variable viewer. I haven't yet found a way to do this (the most obvious way being to right-click the tab for the data being examined). So I'm not sure if this functionality exists. Can anyone confirm or deny (hopefully the former) whether this functionality exists? If it does, how is it done?
As an example, suppose you had a class file myClass.m in the current working directory:
% myClass.m
%----------
classdef myClass
properties
structArray1
end % properties
end % class
Now suppose you issued the following commands:
objectName = myClass
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray(1:3)=rand(1,3)
openvar('objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray')
You are now examining a slew of data within a deeply nested data structure. Normally, the data would have been the result of computation other than the rand statement above, and I would have browsed to it manually rather than using the openvar statement above. So I would not normally have readily available the text for the expression
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray
I have to manually type it in at the command line if I want to use it in a Matlab expression for further computation. It'd be so great if I could somehow point to the tab for that data in the variable explorer and somehow have the expression for the data copied to the clipboard. That way, I can paste it to the command line.
AFTERNOTE:
If there's no way to do this, then as an alternative to manually typing in the whole expression above, is there a way to access the corresponding data object (or a copy thereof) programmatically through the variable explorer window object? This assumes, of course, that the variable explorer is itself a data object as well, through which properties can be accessed. If so, maybe it has a property (perhaps deeply nested) that represents the expression for data in the tab that currently has the focus. If so, I can write a function to retrieve the corresponding data object.
I found that if I undock a tab from the Variables editor, I can select the variable name by double-clicking the variable name in the tab.
Sorry for the ambiguity in wording, but "tab" use to mean the protrusion in the data sheet for displaying the name of the data sheet. Nowadays, "tab" means the whole data sheet. In the first sentence above, I mean the protrusion, which unfortunately doesn't have a distinct name these days (at least none of which I'm aware).
After copying and pasting the variable name from the protrusion, the tab can be docked, which seems to put it back into its original place.

Finding out which function, model or script created a variable in a workspace

I'm using a simulationenvironment in matlab that's consisting of multiple scripts, functions and simulink models. Now I want to find out which of These created a specific variable in my Base-Workspace. Is there a way of finding this out?
One cannot trace back how a variable was created, but you may find the possible candidates that might create the variable.
If you know the name of the variable (let's say is 'my_var'), the use the 'Find files...' from the Edit menu (the usual key biding is [Ctrl]+[Shift]+[F]) to look into all files that containing the text my_var. Do not forget to configure the containing folder to include other paths than the current one, if you're calling some package/toolbox-level scripts.

How to alter the formatting of a single member of my type in Powershell?

I have a set of C# classes that each have a ulong member or two. Powershell outputs these by default as 10-base numbers, but I'd like to show them as hex numbers with a 0x prefix. I'm trying to figure out how to do this right with .ps1xml files.
The first thing I tried was to add a types.ps1xml file that adds a script property with the same name as the one I want to replace. Works fine if I give it a different name (i.e. add a new member) but crashes the ISE if I use the same name as an existing one, like this:
<Members>
<ScriptProperty>
<Name>ForeignId</Name>
<GetScriptBlock>'0x{0:x16}' -f $this.ForeignId</GetScriptBlock>
</ScriptProperty>
</Members>
I assume this is an infinite recursion issue.
Maybe what I really want to do is change the formatting! So I started looking at making a format.ps1xml and using <FormatString>, but now it seems I need to define the formatting completely. I must specify every member I want, and I must do it for all the views I might want. Well, that's a lot of work..
I just want to change the formatting of a single member without adding a new member. Is that possible?
Ran across this a couple of days ago. Maybe useful?
http://poshoholic.com/2008/07/05/essential-powershell-define-default-properties-for-custom-objects/