Link to home
Start Free TrialLog in
Avatar of compdigit44
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

Open in new window

Avatar of Joshua Grantom
Joshua Grantom
Flag of United States of America image

I made a few changes that I can see. I do not have access to PowerCLI so I cannot test it.

If (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue))
{ Add-PSSnapin VMware.VimAutomation.Core}


#$viservers = "vcenter1","vcenter2","vcenter3","vcenter4"
$viservers = "serverABC234"

$outFilelocation = "C:\Work\Script_Logs\VMware" #Your Output location

ForEach ($singleViserver in $viservers)
{

Connect-VIServer $singleViserver
$HostReport = @()

Get-VMHost | Select @{N="Cluster Name";E={($_ | Get-Cluster).Name}},Name,@{N="Location";E={switch -wildcard ($_.Name){       
    "serverabc" {"Rack 832"; break}
	"servercde" {"Rack 744"; break}
	default {"Unknown location"; break}
    }}},Notes,Version,Build,Model,ProcessorType,
    @{N="NumCPU";E={($_ | Get-View).Hardware.CpuInfo.NumCpuPackages}},
    @{N="Cores";E={($_ | Get-View).Hardware.CpuInfo.NumCpuCores}} | Export-Csv "$outFilelocation\VM-host-info-$singleViserver.csv" –NoTypeInformation

Disconnect-VIServer -Server $singleViserver -Confirm:$false -ErrorAction SilentlyContinue
}
Write-Host "`n-=<SCRIPT COMPLETE>=-" -ForegroundColor Yellow

Open in new window

Avatar of compdigit44
compdigit44

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
Avatar of Joshua Grantom
Joshua Grantom
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It worked ...thanks again :-)
Glad to help