any body can help me ?
the real condition
like this
vmname (xyz) , can i split this ?
i use this code
&{foreach($vm in (Get-VM)) {
$vm.ExtensionData.Guest.Net | select -Property @{N='VM';E={$vm.Name}},
@{N='OS';E={$vm.Guest.OSFullName}},
@{N="NumCPU";E={$vm.NumCPU}},
@{N="MemoryMB";E={$vm.MemoryMB}},
@{N='IP';E={[string]::Join(',',($vm.Guest.IPAddress | Where {($_.Split(".")).length -eq 4}))}},
@{N='Gateway';E={[string]::Join(',',($vm.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute | %{if($_.Gateway.IpAddress){$_.Gateway.IpAddress}}))}},
@{N='Subnet Mask';E={
$dec = [Convert]::ToUInt32($(('1' * $_.IpConfig.IpAddress[0].PrefixLength).PadRight(32, '0')), 2)
$DottedIP = $( For ($i = 3; $i -gt -1; $i--) {
$Remainder = $dec % [Math]::Pow(256, $i)
( $dec - $Remainder) / [Math]::Pow(256, $i)
$dec = $Remainder
} )
[String]::Join('.', $DottedIP)
}},
@{N="DNS";E={[string]::Join(',',($vm.ExtensionData.Guest.IpStack.DnsConfig.IpAddress))}},
@{N='MAC';E={[string]::Join(',',$_.MacAddress)}}
}
} | Export-Csv -NoTypeInformation C:\Users\xyz\Desktop\xyz.csv
Thank you all
Try replacing that line with
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear LucD, thank you sir its work,
please help me more about pic name ? ANH .PAS etc
Thank You so much
Not sure what you mean.
Do you want the text between parenthesis in a separate column?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes yes yes,
how great you are sir, thx u
Replace that one line with these 2 lines.
You can change the name of the additional column (here 'VMInfo') to whatever you want.
@{N='VMInfo';E={$vm.Name.split('()')[1]}},
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear Mr LucD
How are you? I hope you are well.
i have problem with this case,
example :
Header 1 | Header 2 | Header 3 |
---|---|---|
Before | abc | xyz |
After | abc(xyz) | xyz |
im still get error after i try to edit this code i want to in my table like after.
this is the code
$dcName = 'XYZ'
$vms = Get-Datacenter -Name $dcName | Get-VM | where { $_.Name -notmatch "test|clone" }
$maxIP = 2
$maxGateway = 2
$maxMask = 2
$vms | ForEach-Object -Process {
$vm = $_
$vm.ExtensionData.Guest.Net |
Sort-Object -Unique |
ForEach-Object -Process {
$obj = [ordered]@{
Hostname = $vm.Name.split('(')[0].TrimEnd(' ')
State = $vm.PowerState
'PIC Aplikasi' = $vm.Name.split('()')[1]
OS = $vm.Guest.OSFullName
CoreCPU = $vm.NumCPU
MemoryGB = $vm.MemoryGB
StatusVM = "Production"
}
1..$maxIP | % { $obj.Add("IP$($_)", '') }
1..$maxGateway | % { $obj.Add("GW$($_)", '') }
1..$maxMask | % { $obj.Add("Mask$($_)", '') }
$i = 1
$vm.Extensiondata.Guest.Net.IPAddress | Where { $_ -and ($_.Split(".")).length -eq 4 -and $i -le $maxIP } |
Sort-Object -Unique |
ForEach-Object -Process {
$obj.Item("IP$($i)") = $_
$i++
}
$i = 1
$vm.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute.Gateway.IpAddress | Where { $_ -and ($_.Split(".")).length -eq 4 -and $i -le $maxGateway } |
Sort-Object -Unique |
ForEach-Object -Process {
$obj.Item("GW$($i)") = $_
$i++
}
$j = 1
$vm.ExtensionData.Guest.Net.IpConfig.IpAddress.PrefixLength | where { $_ -le 32 -and $j -le $maxMask } |
Sort-Object -Unique |
ForEach-Object -Process {
$dec = [Convert]::ToUInt32($(('1' * $_).PadRight(32, '0')), 2)
$DottedIP = $( For ($i = 3; $i -gt -1; $i--) {
$Remainder = $dec % [Math]::Pow(256, $i)
($dec - $Remainder) / [Math]::Pow(256, $i)
$dec = $Remainder
})
$obj.Item("Mask$($j)") = [String]::Join('.', $DottedIP)
$j++
}
New-Object PSObject -Property $obj
}
} | Export-Csv -NoTypeInformation D:\xyz.csv
thx u so much for you helping me to solve this problem
Not sure I'm following.
What is the actual name of that VM?
What error are you getting?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear Mr LucD
Thank you for your fast response.
if im running this code my report look like this
Header 1 | Header 2 |
---|---|
AppOne | xyz |
and what i want see look like
Header 1 | Header 2 |
---|---|
AppOne(xyz) | xyz |
Can you help me for this case ?
Thank You
Tomi Irawan
Ok, try changing the line to
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear Mr LucD
Thank you for the answer but i mean like this
vm name | PIC |
---|---|
AppTest (xyz) | xyz) |
So AppTest (xyz) have another coloum to pic look like table Mr LucD.
if i try command you give me it will only show
AppTest (xyz) only ther is not another coloum.
Thank You
Tomi Irawan
In the original script, you only replace this line
by this line
The rest of the script stays the same.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference