Archive for the ‘powershell’ Category
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
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
now 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.
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
Now the disk info.
get-psdrive Or get-psdrive | where-object {$_."Free" } it shows the free space.
get-hotfix | where-object {$_.HotFixID -eq ‘KB982293’ } <> get hotfix list
get-process | where-object {$_.Handles -gt ‘888’ } <> Shows process with more handles than 888 Change the value for other items
get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ }
for other disk change the C or F value
Get-ClusterNetworkInterface
Get-ClusterNetworkInterface | where-object {$_.State -eq ‘Up’ } <> or down
Get-ClusterNetworkInterface | where-object {$_.State -ne ‘Up’ }
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.
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
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
In the basic you can get any info and create a html file.
Technorati 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
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
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
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
now 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.
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
Now the disk info.
get-psdrive Or get-psdrive | where-object {$_."Free" } it shows the free space.
get-hotfix | where-object {$_.HotFixID -eq ‘KB982293’ } <> get hotfix list
get-process | where-object {$_.Handles -gt ‘888’ } <> Shows process with more handles than 888 Change the value for other items
get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ }
for other disk change the C or F value
Get-ClusterNetworkInterface
Get-ClusterNetworkInterface | where-object {$_.State -eq ‘Up’ } <> or down
Get-ClusterNetworkInterface | where-object {$_.State -ne ‘Up’ }
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.
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
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
In the basic you can get any info and create a html file.
Technorati 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
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
If you are Building a Webfarm you need often Test websites and all the Sites needs to be the same
Well below is a powershell Scripts that copy the Site and Creates a new one On the Same Server.
# NAME: Copy-Website.ps1
#
# AUTHOR: Robert Smit
# EMAIL: robert.smit@aca-computers.nl
#
# COMMENT: Script to create a Copy-Website.
#
# You have a royalty-free right to use, modify, reproduce, and
# distribute this script file in any way you find useful, provided that
# you agree that the creator, owner above has no warranty, obligations,
# or liability for such use.
#
# VERSION HISTORY:
# 1.0 4.06.2011 – Initial release
#
###########################################################################
ImportSystemModules
#Importing Microsofts PowerShell-modules
#Set ExecutionPolicy
#Set-ExecutionPolicy -scope LocalMachine RemoteSigned –force
#Importing Microsofts PowerShell-module for administering IIS
Import-Module WebAdministration
#List website
Write-Host "List IIS Website…" -ForegroundColor yellow
get-Item IIS:Sites*
#Variables for creating the new Website
#
#
$sourceweb = Read-Host "Enter the Website to Copy"
$destinationweb = Read-Host "Enter the New Websitename"
$ChangedDemoSiteBinding = Read-Host "Enter the Hostheader of the website"
$LogDir = Read-Host "Enter the website path of the new website"
#Copy website
Write-Host "copy IIS Website…" -ForegroundColor yellow
copy-Item IIS:Sites$sourceweb -destination IIS:Sites$destinationweb
#Create Application pool
Write-Host "Create Application pool…" -ForegroundColor yellow
New-WebAppPool $destinationweb
#Link Application pool
Write-Host "Link Application pool…" -ForegroundColor yellow
get-ItemProperty IIS:Sites$destinationweb
Set-ItemProperty IIS:Sites$destinationweb -name applicationPool -value "$destinationweb"
#Set nieuwe Host name
Write-Host "Set nieuwe Host name…" -ForegroundColor yellow
get-Item IIS:Sites$destinationweb
Set-ItemProperty IIS:Sites$destinationweb -Name bindings -Value @{protocol="http";bindingInformation="192.168.123.1:80:$ChangedDemoSiteBinding"} #change the IP here
#Set new Path
Write-Host "Set new Path…" -ForegroundColor yellow
get-Item IIS:Sites$destinationweb
Set-ItemProperty IIS:Sites$destinationweb -Name physicalPath -Value "$LogDir"
#Scopy site
#Write-Host "Scopy site …" -ForegroundColor yellow
#Copy-Item "C:Put your folder here*" $LogDir # change The Filepath here
#Set user account
Write-Host "Set user account…" -ForegroundColor yellow
Set-ItemProperty IIS:Sites$destinationweb -Name Username -Value "Username"
Set-ItemProperty IIS:Sites$destinationweb -Name Password -Value "Password"