compdigit44
asked on
Powershell Error "Select-Object : A positional parameter cannot be found that accepts argum 'System.Object[]'."
I am not a strong powershell person and my Powercli script is failing with the following message: "Select-Object : A positional parameter cannot be found that accepts argum 'System.Object[]'." I have tried for hours to get this to work and have had no luck.. What am I missing.
if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {
Add-PSSnapin VMware.VimAutomation.Core}
#$viservers = "vcenter1","vcenter2","vcenter3","vcenter4"
$outFile = "C:\Work\Script_Logs\VMware\VM-host-info.csv" #Your Output location
$viservers = "serverABC234"
foreach ($singleViserver in $viservers)
{
Connect-VIServer $singleViserver
$HostReport = @()
Get-VMHost | Select @{N="Cluster Name";E={($_ | Get-Cluster).Name}}, Name,
@{label="Location";expression={switch -wildcard ($_.Name)
{
"serverabc" {"Rack 832"}
"servercde" {"Rack 744"}
default {"Unknown location"}
}}} Notes, Version, Build, Model, ProcessorType
@{N="NumCPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},
@{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}} | Export-Csv $outFile –NoTypeInformation
DisConnect-VIServer -Server $viservers -Confirm:$false -ErrorAction SilentlyContinue
Write-Host "`n-=<SCRIPT COMPLETE>=-" -ForegroundColor Yellow
ASKER
Thanks for you help but getting errors try to run they script. I does not like the syntax around -ForegroundColor and also claim a terminator is missing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked ...thanks again :-)
Glad to help
Open in new window