Search found 22 matches

by drpiet
Thu Sep 03, 2020 4:06 am
Forum: PowerShell
Topic: Something like get-variable for array elements
Replies: 13
Views: 25452

Re: Something like get-variable for array elements

I'm glad to read it.
I know isn't something that we might use a lot, but on my specific case, I didn't finish yet replacing things, but it will save me a few hundreds lines of code. :D
by drpiet
Mon Aug 31, 2020 4:14 am
Forum: PowerShell
Topic: Something like get-variable for array elements
Replies: 13
Views: 25452

Re: Something like get-variable for array elements

Thank you
I guess.
by drpiet
Fri Aug 28, 2020 2:18 pm
Forum: PowerShell
Topic: Something like get-variable for array elements
Replies: 13
Views: 25452

Re: Something like get-variable for array elements

jvierra, I will try one more time. I want to read the value of an item inside a PSObject. Of course I know how to do it. The part you don't understand is that I want to use a value stored on a variable to form the name of the object to retrieve. So, I need to retrieve the value of the following vari...
by drpiet
Fri Aug 28, 2020 1:56 pm
Forum: PowerShell
Topic: Something like get-variable for array elements
Replies: 13
Views: 25452

Re: Something like get-variable for array elements

I guess I found a way to do it, probably not the best but it looks like it works (needs to test it in production). I have a PSCustomObject with these values (again, on production is way bigger): $test.role1 = R1 $test.DataC1 = DC1 $test.ASize1 = AS1 $test.role2 = R2 $test.DataC2 = DC2 $test.ASize2 =...
by drpiet
Fri Aug 28, 2020 7:43 am
Forum: PowerShell
Topic: Something like get-variable for array elements
Replies: 13
Views: 25452

Re: Something like get-variable for array elements

What you mean that the first example is not possible? If I have a variable called Fruit1 and its content is "Apple", I can do this: $fruit1 = "Apple" $number = 1 $CurrentValue = (Get-Variable ('Fruit' + $number)).value $CurrentValue -> Apple Now the content of $CurrentValue will ...
by drpiet
Fri Aug 28, 2020 4:12 am
Forum: PowerShell
Topic: Something like get-variable for array elements
Replies: 13
Views: 25452

Re: Something like get-variable for array elements

Well, the original object is a PSCustomObject, but doing something as simple as $test = @($Array)
Now yes, I have an array that have the same problem.

The point is if there is a way to do what I'm trying to accomplish, with either of those two type of objects?
by drpiet
Thu Aug 27, 2020 2:35 pm
Forum: PowerShell
Topic: Something like get-variable for array elements
Replies: 13
Views: 25452

Something like get-variable for array elements

Hello guys, In a case where you have a lot of variables named like this: - Fruit1 - Fruit2 - Fruit3 - Fruit4 I can then on my code read the values using a loop, for example: for ($q = 1; $q -le 5; $q++) { $CurrentValue = (Get-Variable ('Fruit' + $q)).value } And that's great and works perfectly. Now...
by drpiet
Fri Jul 27, 2018 11:18 am
Forum: PowerShell
Topic: Different results on a command run as job and regularly
Replies: 20
Views: 6907

Re: Different results on a command run as job and regularly

I appreciate your help, but there is absolutely nothing to try. This is not based on assumptions, just powershell knowledge.
Thanks
by drpiet
Fri Jul 27, 2018 10:12 am
Forum: PowerShell
Topic: Different results on a command run as job and regularly
Replies: 20
Views: 6907

Re: Different results on a command run as job and regularly

Don't take me wrong, I appreciate your answers and your time.
But the code you posted the only thing that does different is running the command inside a try/catch structure, so I know that will not change the result. For sure is a better way to code, but is not what I'm looking for right now.