Powershell Management Commands Easy Step by Step get Server info in HTML ConvertTo-

Powershell is a great way to get your server info. like a poor mans management Tool.

I will explain the ConvertTo command easy to use and with a scheduler it can be very handy.

And I will show several Powershell commands that can be handy to find things.

 

What is the Converto- ?

The ConvertTo-Html cmdlet converts .NET Framework objects into HTML that can be displayed in a Web browser. You can  use this cmdlet to display the output of a command in a Web page.

You can use the parameters of ConvertTo-Html to select object properties, to specify a table or list format, to specify the HTML page title, to add text before and after the object, and to return only the table or list fragment, instead of a strict DTD page. When you submit multiple objects to ConvertTo-Html, Windows PowerShell creates the table (or list) based on the properties of the first object that you submit. If the remaining objects do not have one of the specified properties,  the property value of that object is an empty cell. If the remaining objects have additional properties, those property values are not included in the file.

Some Samples to get things working

get-service A*  this shows all the services starting with an A

image Or in the full context

get-service A* | ConvertTo-Html -title "Windows Services: Server01" -body (get-date) -pre "<P>Generated by Corporate IT</P>" -post "For details, contact Corporate IT." > services.htm; ii services.htm

imagenow that you can get the info in HTLM , you can place the info in a webserver and on a collection page you can see the status of your server.

imageimage

Get-Service  <> shows the full list

get-service | ft -Property name, status  <>or in a table

get-service | where-object {$_.Status -eq "Running"}   <> shows only the running services. or the stopped services

imageimage

 

Now the disk info.

get-psdrive  Or get-psdrive | where-object {$_."Free" }  it shows the free space.

imageimage 

 

get-hotfix | where-object {$_.HotFixID -eq ‘KB982293’ }  <> get hotfix list

image

get-process | where-object {$_.Handles -gt ‘888’ }  <> Shows process with more handles than 888 Change the value for other items

image

 

get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ }

image for other disk change the C or F value

Get-ClusterNetworkInterface

image

Get-ClusterNetworkInterface | where-object {$_.State -eq ‘Up’ } <> or down

Get-ClusterNetworkInterface | where-object {$_.State -ne ‘Up’ }  

image

 

Now that we have a basic set of command we will use this in the convertTo-HTML to get the output in html.

 

get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ } | ConvertTo-Html -as Table "List C drive and F drive" -body (get-date) -pre "<P>Generated On Myserver01</P>" > Listdisk.htm; ii ListDisk.htm

creates the site and in ii it opens the site.

image  imageimage

get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ } | ConvertTo-Html -as Table -Title "List C drive and F drive" -body (get-date) -pre "<P>Generated On Myserver01</P>" > Listdisk.htm; ii ListDisk.htm

get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ } | ConvertTo-Html -as list -Title "List C drive and F drive" -body (get-date) -pre "<P>Generated On Myserver01</P>" > Listdisk.htm; ii ListDisk.htm

 

 

 

There are several options for the listing format play with it and get your perfect list.

get-service A* | ConvertTo-Html -title "Windows Services: Server01" -body (get-date) -pre "<P>Generated by Corporate IT</P>" -post "For details, contact Corporate IT." > services.htm; ii services.htm

imageimage

get-service | where-object {$_.Status -eq "Stopped"} | ConvertTo-Html -title "Windows Services Stopped on ServerName " -body (get-date) -pre "<P>Generated On Myserver01 </P>" > servicesstoped.htm; ii servicesstoped.htm

get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ } | ConvertTo-Html -title "List C drive and F drive" -body (get-date) -pre "<P>Generated On Myserver01 </P>" > Listdisk.htm; ii ListDisk.htm

 

image

 

In the basic you can get any info and create a html file.

Technorati Tags: ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
WordPress Tags: Powershell,Management,Commands,Easy,Step,Server,info,HTML,ConvertTo,Tool,Converto,Framework,objects,output,text,cell,Some,services,context,Corporate,HTLM,collection,status,Service,disk,Free,HotFixID,Change,items,Name,ClusterNetworkInterface,State,Table,List,Listdisk,Title,ServerName,parameters,options,cmdlet,psdrive,hotfix

Posted July 25, 2011 by Robert Smit in powershell, ServerManagement

  • Tag