Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell list of websites using get-website?

Tags:

powershell

iis

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" ?

like image 649
Mike J Avatar asked Oct 29 '12 17:10

Mike J


1 Answers

try

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

-edit after comment:

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
like image 139
CB. Avatar answered Sep 22 '22 07:09

CB.