Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Remove Characters from Variable

$
0
0

Good day, I have a couple of conundrums with the use of variables from third-party cmdlets.

I"m trying to use Equallogic Powershell addin to build a variable that can be passed to Microsoft iSCSI cmdlet.

To build the initial variable I use: $iscsitarget = Get-EqlVolume -VolumeName TZ | select iSCSITargetName

The result is:

iSCSITargetName
---------------
iqn.2001-05.com.equallogic:0-8a0906-e4819c90c-a5347fe0a2d533b3-tz

The variable in it's raw form cannot be used by the iSCSI cmdlet, due to unacceptable characters. When I pipe this over to an environment variable, this is the result:

iSCSITarget                    @{iSCSITargetName=iqn.2001-05.com.equallogic:0-8a0906-e4819c90c-a5347fe0a2d533b3-tz}

The @, {, } are causing this problem, so I tried exporting the initial variable as a string, as such:

$iscsitarget2 = $iscsitarget | Out-String

It seems if I remove 2 characters from the beginning the results are not what I need. Removing more characters and the variable string just becomes "...", rendering the variable useless.

So my question is can I remove characters from a variable that isn't a string and if so what is the command? Or, should I be doing things a different way? I am not as proficient in powershell, what you see is about the extent of my skills.

What's funny is when I use this variable with the Equallogic powershell addin it says there are illegal characters as well. It seem this was created more for reporting than scripting.

I hope to hear back from someone. At this point my option is to throw in the towel or switch over to PERL, which I know nothing about.

Thank you!!


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>