Hi,
I'm trying to write a table to the console, from the content of an object (example below).
As Write-Output is the last command in the pipeline it should (according to PS documentation) display the output in the console, and it does. But not after making a successful connection with Get-VIServer. If I comment out the Get-VIServer line it works.
Is this a problem in the Get-VIServer CmdLet or am i not thinking of something, and are there any workarounds.
add-PSSnapin VMware.VimAutomation.Core
Get-VIServer "Servername"
$strings = "one","two","three"
ForEach ($string in $strings) {
$obj = New-Object PSObject
$obj | Add-Member NoteProperty Original $string
$obj | Add-Member NoteProperty Uppercase $string.ToUpper()
$obj | Add-Member NoteProperty Lowercase $string.ToLower()
Write-Output $obj
}
Hi,
I'm trying to write a table to the console, from the content of an object (example below).
As Write-Output is the last command in the pipeline it should (according to PS documentation) display the output in the console, and it does. But not after making a successful connection with Get-VIServer. If I comment out the Get-VIServer line it works.
Is this a problem in the Get-VIServer CmdLet or am i not thinking of something, and are there any workarounds.
add-PSSnapin VMware.VimAutomation.Core
Get-VIServer "Servername"
$strings = "one","two","three"
ForEach ($string in $strings) {
$obj = New-Object PSObject
$obj | Add-Member NoteProperty Original $string
$obj | Add-Member NoteProperty Uppercase $string.ToUpper()
$obj | Add-Member NoteProperty Lowercase $string.ToLower()
Write-Output $obj
}
The Beta Get-VIServer has some unwanted output that interferes with PowerShell's default formatting. To work around it, do Get-VIServer <your arguments> > $null.
It works for me.
PS C:\Documents and Settings\hrottenberg\My Documents\WindowsPowerShell\scripts\> ./test2 Name Port User ---- ---- ---- mojito 443 <user> Original : one Uppercase : ONE Lowercase : one Original : two Uppercase : TWO Lowercase : two Original : three Uppercase : THREE Lowercase : three
Hal Rottenberg
Co-Host, PowerScripting Podcast (http://powerscripting.net)
For me it doesn't.
Powershell 1.0 v 6.0.5430.0.
VI Toolkit build build 81531.
Tried it from the VI Toolkit shell and from PowershellPlus.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm running a later build, it's possible this is related to a fixed bug.
To the original poster...just don't put add-pssnapin and get-viserver in your script. Run your scripts from a session with the snapin already loaded, and invoke get-viserver before executing scripts.
Hal Rottenberg
Co-Host, PowerScripting Podcast (http://powerscripting.net)
Hi,
I'm trying to write a table to the console, from the content of an object (example below).
As Write-Output is the last command in the pipeline it should (according to PS documentation) display the output in the console, and it does. But not after making a successful connection with Get-VIServer. If I comment out the Get-VIServer line it works.
Is this a problem in the Get-VIServer CmdLet or am i not thinking of something, and are there any workarounds.
add-PSSnapin VMware.VimAutomation.Core
Get-VIServer "Servername"
$strings = "one","two","three"
ForEach ($string in $strings) {
$obj = New-Object PSObject
$obj | Add-Member NoteProperty Original $string
$obj | Add-Member NoteProperty Uppercase $string.ToUpper()
$obj | Add-Member NoteProperty Lowercase $string.ToLower()
Write-Output $obj
}
The Beta Get-VIServer has some unwanted output that interferes with PowerShell's default formatting. To work around it, do Get-VIServer <your arguments> > $null.
Thank you,
These both seem to work
Get-VIServer "servername" > $null
Get-VIServer "servername" | Out-Null
@halr9000:
Is there a good reason for not adding snapins and connecting to the server from the script? I like better to start from a basic PowerShell Console and add whichever extensions i want to use.
This is what i use for adding the snapin:
If (-Not(Get-PSSnapin -registered | Where-Object {$_.name -eq "VMware.VimAutomation.Core"}))
{Write-Error "VI Toolkit isn't installed, the script cannot continue"; Break}
Else
{Write-Host "VI Toolkit is installed, found snap-in"}
If (-Not(Get-PSSnapin | Where-Object {$_.name -eq "VMware.VimAutomation.Core"}))
{Write-Host "Loading VI Toolkit snap-in"; add-PSSnapin VMware.VimAutomation.Core}
Else
{Write-Host "Snap-in is already loaded"}
Is there a good reason for not adding snapins and connecting to the server from the script? I like better to start from a basic PowerShell Console and add whichever extensions i want to use.
Well I guess for the most part its just a matter of preference. However, RAM is cheap, so I do things like the below in my $profile:
# --------------------------------------------------------------------------- # Add third-party snapins # --------------------------------------------------------------------------- $snapins = "psmsi", # Windows Installer PowerShell Extensions "PshX-SAPIEN", # AD cmdlets from Sapien "Quest.ActiveRoles.ADManagement", # more AD stuff "PowerGadgets", "VMware.VimAutomation.Core", "PoshHttp", "NetCmdlets" $snapins | ForEach-Object { if ( Get-PSSnapin -Registered $_ -ErrorAction SilentlyContinue ) { Add-PSSnapin $_ } # --------------------------------------------------------------------------- # Load function / filter definition library # --------------------------------------------------------------------------- Get-ChildItem scripts:\lib-*.ps1 | % { . $_ write-host "Loading library file:`t$($_.name)" }
Hal Rottenberg
Co-Host, PowerScripting Podcast (http://powerscripting.net)