VMware Cloud Community
FrankG203
Enthusiast
Enthusiast
Jump to solution

invoke-vmscript and truncation

Hi guys - I am running the below script to gather all conditional forwarders from the DCs in our environment, for the systems that have more then 3 or 4 "MasterServers" the output in truncated, I have tried all sort of combinations to get this work and I have not been successful. 

Any help would be appreciated

clear

# Connect to both vCenters
# Connect-VIServer -Server $hosts

$xxxxxxx = Get-Credential
$scriptText = 'Get-DnsServerZone | ? {$_.zonetype -eq "forwarder"} | Select ZoneName, MasterServers'
$vmList = Get-VM -Name "xxxxxxx" -Server $hosts

foreach($vm in $vmList){

$vmName = $vm.name
$vmName
Out-File -Append -Encoding default -FilePath c:\scripts\dnslog.txt -InputObject $vmName

$scriptOutput = invoke-VMscript -vm $vm -Server $hosts -scripttext $scriptText -GuestCredential $xxxxxx
$scriptOutput
Out-File -Append -Encoding default -FilePath c:\scripts\dnslog.txt -InputObject $scriptOutput
}

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The MasterServers property is an array of Strings, so you could use a calculated property and the Join operator

$scriptText = 'Get-DnsServerZone | ? {$_.zonetype -eq "forwarder"} | Select ZoneName, @{N="MasterServers";E={$_.MasterServers -join '|'}}'

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

The object returned by Invoke-VMScript has multiple properties.
If you leave it to the PS engine on how to display the object some properties might be missing or incomplete.

The actual output from the code in your case is located in $scriptOutput.ScriptOutput


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
FrankG203
Enthusiast
Enthusiast
Jump to solution

Thanks LucD for the response, I have tried this and it still does not seem to be working. I added Scriptoutput and it is still truncating the IPs, any other ideas?

PS C:\Users\> $FormatEnumerationLimit
-1

PS C:\Users\> $PSVersionTable.PSVersion

Major Minor Build Revision
----- ----- ----- --------
5 1 14409 1027

 

PowerCLI Version
----------------
VMware.PowerCLI 12.5.0 build 19195797
---------------
Component Versions
---------------
VMware Common PowerCLI Component 12.5 build 19093563
VMware Cis Core PowerCLI Component PowerCLI Component 12.5 build 19093567
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.5 build 19093566

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

How did you change your code?
And what is the output?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
FrankG203
Enthusiast
Enthusiast
Jump to solution

Even if i run this code or any similar code to do this it does not display the output properly. For example running this from the DC locally

Get-DnsServerZone | ? {$_.zonetype -eq "forwarder"} | Select-Object ZoneName, MasterServers | Format-Table -Property * -AutoSize | Out-String -Width 4096

FrankG203_0-1653140827445.png

Its showing 4 IPs but I know there are 6

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

PowerShell by default only shows max 4 properties of an object.
See Discovering objects, properties, and methods - PowerShell | Microsoft Docs

Try with

Get-DnsServerZone | ? {$_.zonetype -eq "forwarder"} | Select-Object *


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
FrankG203
Enthusiast
Enthusiast
Jump to solution

That is just returning all the objects, I am looking to gather all the information under MasterServers

FrankG203_0-1653313987820.png

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then you could do

Get-DnsServerZone | ? {$_.zonetype -eq "forwarder"} | Select-Object -ExpandProperty MasterServers


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
FrankG203
Enthusiast
Enthusiast
Jump to solution

I am having a hard time explaining the issue, the end goal for me is to have two columns in either a text file or csv.

if it is a text file I would like it to be formatted like below

Computer Name

Conditional Forward Name                        IPs

mypc.com                                                   8.8.8.8, 4.4.4.4, 6.6.6.6

mypc2.com                                                 4.4.4.4, 8.8.8.8, 6.6.6.6

I am able to do this but it is cutting it off at 4, I was trying earlier to "dot" into MasterServers and grab "IPAddressToString" property to display ALL the IPs but now my issue is formatting it like above. 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The MasterServers property is an array of Strings, so you could use a calculated property and the Join operator

$scriptText = 'Get-DnsServerZone | ? {$_.zonetype -eq "forwarder"} | Select ZoneName, @{N="MasterServers";E={$_.MasterServers -join '|'}}'

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
FrankG203
Enthusiast
Enthusiast
Jump to solution

That is exactly what I was looking for, thanks for the help LucD!

One question though how does "join" '|" know how to select the "IPAddressToString"  and not any of the others?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The IP addresses are what is shown by default, as you noticed in one of your earlier replies when you did a Select MasterServers.
But they were shown as an array (the curly braces), and only 4 of them due to the default 4 properties rule I mentioned earlier.
You can chose to not rely on what is shown by default for the MasterServers property, and change the calculated property to the IP address property under MasterServers


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
FrankG203
Enthusiast
Enthusiast
Jump to solution

Thanks for all of your help and your explanations..

I had to add the out-string -width 4096 to get this to display properly when running remotely

'Get-DnsServerZone | ? {$_.zonetype -eq "forwarder"} | Select ZoneName, @{N="MasterServers";E={$_.MasterServers -join "|"}} | out-string -width 4096'

Reply
0 Kudos