Just a quick question. I am running lines of code like,
$publicIP = Get-Content (Get-AzureVM -ServiceName $servicename -Name $vmsname | Get-AzureEndpoint | Select { $._vip })
$OSDisk = Get-Content (Get-AzureVM -ServiceName $servicename -Name $vmsname | Get-AzureOSDisk)
And it does get me the IPAddress or the variables, but when trying to put the value into a csv cell, it fails. I think it is because it tries to add the extra labels, but I do not know how to get just the string and set the variable as just that. Does anyone know how to remedy this?
edit:
If the output with:
Get-AzureVM -servicename "vm1" -name "vm1" | Select DNSName | Out-String
is like this:
DNSName
-------
http://example.cloudapp.net/
How do I just put in " http://example.cloudapp.net/ " as a CSV-entry? Right now it is trying to put all of the code block into the CSV which is giving me awful formatting erros.
Select
is an alias for Select-Object
and allows you to take one or more properties from an object and creates a new object with them.
If you want to expand a property into just the value, use the -ExpandProperty
parameter:
Get-AzureVM -servicename "vm1" -name "vm1" | Select -ExpandProperty DNSName
Should give you just http://example.cloudapp.net/
Also, when you want to send data to a CSV, you can pipe objects to the cmdlet Export-CSV
which will use the property names as headers and the objects in the array as rows and the properties as columns.
Example:
Get-ChildItem -File | Select Name, Size | Export-Csv c:\temp\filelist.csv
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.