Добрый день, есть задача:
Необходимо выгрузить данные по всем VM, которые есть в VMware. Установил PowerCLI
Нужна таблица в виде:
on english:
Good day, there is a task:
You need to upload data for all VMS that are available in VMware. Installed PowerCLI
Need a table in the form:
vmname-ttl (lifetime) - project-project owner-admin-real hdd volume - maximum hdd volume.
vmname - ttl (время жизни) - проект - владелец проекта - админ - объем hdd реальный - объем hdd максимальный
.
Нашел похожий скрипт:
PowerShellВыделить код | ||
|
Но вывод в файлик, не совсем понятного вида.
PowerShellВыделить код | ||
|
Если кто делал подобное, пожалуйста подскажите.
На просторах нашел, что ttl не удастся вытащить. Ищу решение, чтобы данные были читабельны.
Есть такой:
get-VM | select Name, @{ l="ProvisionedSpaceGB"; e={[int]$_.ProvisionedSpaceGB}}, @{l="UsedSpaceGB";e={[int]$_.UsedSpaceGB}} | Export-Csv -Path C:\provision.csv
You will have to get those one by one.
Something like this
$adminAttr = Get-CustomAttribute -Name Admin
$ownerAttr = Get-CustomAttribute -Name Owner
$projectNameAttr = Get-CustomAttribute -Name ProjectName
Get-VM |
Select Name,
@{N='TTL';E={(Get-Annotation -CustomAttribute $ttlAttr -Entity $_).Value}},
@{N='Admin';E={(Get-Annotation -CustomAttribute $adminAttr -Entity $_).Value}},
@{N='Owner';E={(Get-Annotation -CustomAttribute $ownerAttr -Entity $_).Value}},
@{N='ProjectName';E={(Get-Annotation -CustomAttribute $projectNameAttr -Entity $_).Value}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What do you mean by 'readable'?
The CSV format is clear text and readable.
The name of each column is shown in the 1st row.
If TTL means how old a VM is, that is currently not really possible.
You could look at the events (Get-VIEvent) to find out when a VM was created.
But events are only kept for maximum 1 year.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
referring to the figures, for example, 40, not 40,125372051261365413665771485.
I solved this problem with the script below. Now the display in Excel is normal.
It turns out that you need to correct the script so that it pulls out the data that is on the screenshot. Not all, but what are possible
it turns out that ttl is the period until which the VM is valid
That is a Custom Attribute.
You can retrieve the Value with something like this
Get-VM |
Select Name,
@{N='TTL';E={(Get-Annotation -CustomAttribute $ttlAttr -Entity $_).Value}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much, it works!
I will try to bring to mind that all parameters were:
$ttlAttr = Get-CustomAttribute -Name TTL -Admin -Owner -ProjecrName -ProvisionedSpaceGB -UsedSpaceGB | Export-Csv -Path C:\provision.csv
Get-VM |
Select Name,
@{N='TTL';E={(Get-Annotation -CustomAttribute $ttlAttr -Entity $_).Value}}, @{N='Admin';E={(Get-Annotation -CustomAttribute $AdminAttr -Entity $_).Value}}
You will have to get those one by one.
Something like this
$adminAttr = Get-CustomAttribute -Name Admin
$ownerAttr = Get-CustomAttribute -Name Owner
$projectNameAttr = Get-CustomAttribute -Name ProjectName
Get-VM |
Select Name,
@{N='TTL';E={(Get-Annotation -CustomAttribute $ttlAttr -Entity $_).Value}},
@{N='Admin';E={(Get-Annotation -CustomAttribute $adminAttr -Entity $_).Value}},
@{N='Owner';E={(Get-Annotation -CustomAttribute $ownerAttr -Entity $_).Value}},
@{N='ProjectName';E={(Get-Annotation -CustomAttribute $projectNameAttr -Entity $_).Value}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hank you very much for your help! I will test
If you have time please take a look
$ttlAttr = Get-CustomAttribute -Name TTL
$adminAttr = Get-CustomAttribute -Name Admin
$ownerAttr = Get-CustomAttribute -Name Owner
$projectNameAttr = Get-CustomAttribute -Name ProjectName
Get-VM |
Select Name,
@{N='TTL';E={(Get-Annotation -CustomAttribute $ttlAttr -Entity $_).Value}},
@{N='Admin';E={(Get-Annotation -CustomAttribute $adminAttr -Entity $_).Value}},
@{N='Owner';E={(Get-Annotation -CustomAttribute $ownerAttr -Entity $_).Value}},
@{N='ProjectName';E={(Get-Annotation -CustomAttribute $projectNameAttr -Entity $_).Value}},
@{ l="ProvisionedSpaceGB"; e={[int]$_.ProvisionedSpaceGB}}, @{l="UsedSpaceGB";e={[int]$_.UsedSpaceGB}} | Export-Csv -Path C:\provision.csv
issues on scrin
how to make text instead of question marks
That is most probably due to the fact that the encoding is set to ASCII, which changes special characters to question marks.
Can you try setting the default encoding to UTF8?
[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Understood, I'll look for. Version of Excel 2013. Perhaps in later versions it is possible to set the default.
I tried to open this "provision" file in notepad, then convert it to UTF-8 and save it. Then opened in Excel, displayed also-question marks
When it is saved as a CSV its probably too late.
Excel only sees question marks.
You will have to do it in the PowerShell session where you create the CSV.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks! Got it !
That is, the command
[Console]:: OutputEncoding = [Text.UTF8Encoding]:: UTF8
insert into the script ? or before the script?
I Use Vmware PowerCLI 6.5
Both would work, just make sure it is executed before you run the Get-VM and the Select from the script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Class. Thank you for your help !
$ttlAttr = Get-CustomAttribute -Name TTL
$adminAttr = Get-CustomAttribute -Name Admin
$ownerAttr = Get-CustomAttribute -Name Owner
$projectNameAttr = Get-CustomAttribute -Name ProjectName
Get-VM |
Select Name,
@{N='TTL';E={(Get-Annotation -CustomAttribute $ttlAttr -Entity $_).Value}},
@{N='Admin';E={(Get-Annotation -CustomAttribute $adminAttr -Entity $_).Value}},
@{N='Owner';E={(Get-Annotation -CustomAttribute $ownerAttr -Entity $_).Value}},
@{N='ProjectName';E={(Get-Annotation -CustomAttribute $projectNameAttr -Entity $_).Value}},
@{ l="ProvisionedSpaceGB"; e={[int]$_.ProvisionedSpaceGB}}, @{l="UsedSpaceGB";e={[int]$_.UsedSpaceGB}} | Export-Csv -Path C:\provision.csv -Encoding UTF8 -NoTypeInformation
Does it get rid of the question marks in the CSV that way?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, open excel, click data from a text / CSV file. Choosing UTF-8 encoding
Perfect!
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference