16

I'm having some troubles with a basic powershell command.

If i run get-website (after enabling the webadministration snappin) and running "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -ImportSystemModules", I see a list of the 10 or so websites on my IIS 7.0 server on Server 2008 Standard (SP2, not R2). It works as expected by listing these items:

  • name
  • ID
  • State
  • Physical Path
  • Bindings

But when I do:

get-website | export-csv C:\my_list.csv

I get many more items with "Microsoft.IIs.PowerShell.Framework.ConfigurationElement" instead of the actual value.

When it's exported to CSV it also says "Microsoft.IIs.PowerShell.Framework.ConfigurationElement" for bindings when it didn't prior (when the output was in the shell).

It's sort of halfway there...

Is there a way I can modify the one-liner so I can have a list of websites with all details without "Microsoft.IIs.PowerShell.Framework.ConfigurationElement" ?

4

1 に答える 1

29

試す

get-website | select name,id,state, physicalpath,
@{n="Bindings"; e= { ($_.bindings | select -expa collection) -join ';' }} |
Export-Csv -NoTypeInformation -Path C:\my_list.csv

-コメント後に編集:

get-website | select name,id,state,physicalpath, 
@{n="Bindings"; e= { ($_.bindings | select -expa collection) -join ';' }} ,
@{n="LogFile";e={ $_.logfile | select -expa directory}}, 
@{n="attributes"; e={($_.attributes | % { $_.name + "=" + $_.value }) -join ';' }} |
Export-Csv -NoTypeInformation -Path C:\my_list.csv
于 2012-10-29T18:14:22.287 に答える