I have this line of code-
$T = Get-VM $M.Name | Get-Harddisk | Select StorageFormat
It works fine unless there is a / character in the name. (in $M.Name), in which case it errors and fails. Is there a simple way around this?
Thanks for any suggestion
In that case, go for the Replace method and only replace the slash.
Like this
$name = 'Te st/123'
Get-VM -Name $name.Replace('/','%2F')
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Use the URL decoding functionality
Something like this
$name = 'Test/123'
Get-VM -Name ([uri]::EscapeDataString($name))
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This seems to expand spaces to %20 so it doesn't find the names.
In that case, go for the Replace method and only replace the slash.
Like this
$name = 'Te st/123'
Get-VM -Name $name.Replace('/','%2F')
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That worked perfectly. Thank you very much for the help.
Randy
