Link to home
Start Free TrialLog in
Avatar of Kelly Garcia
Kelly GarciaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Powershell HashTables

HI,

I have this powershell script:

Get-qadcomputer kellytestmachine | select Name, OSName, OSServicePack, ComputerRole, dNSHostName

all the items that are selected, I want them to be a different name for the csv file.

so I tried this for test however it failed:

Get-qadcomputer kellytestmachine | select Name, OSName, @{n="OS Service Pack";e={"$_.OSServicePack"}}, ComputerRole, dNSHostName

Thank you in advance
Avatar of oBdA
oBdA

Remove the quotes inside the expression.
Get-qadcomputer kellytestmachine | select Name, OSName, @{n="OS Service Pack"; e={$_.OSServicePack}}, ComputerRole, dNSHostName

Open in new window

Avatar of Kelly Garcia

ASKER

is this a better way of writing the script?

$ServerName = "kellytestmachine", "kellytestmachine2"

foreach ($s in $serverName) {

$servinfo = @{
Name = Get-Qadcomputer $_ | select Name 
OSName = Get-Qadcomputer $_ | select OsName
ServicePack = Get-Qadcomputer $_ | select OsServicePack
DiskSpace (GB) = Get-WmiObject win32_logicaldisk -ComputerName $_
#IPAddress = code
#MacAddress = code
#Server Roles and Features = code
}


} | Export-Csv serverinfo.csv -NoTypeInformation

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

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