Wednesday, 16 October 2013

Get-SQLServer2.ps1

  1. #Requires -Version 3.0 
  2. <# 
  3. .SYNOPSIS 
  4.     This script Gets a list of SQL Severs on the Subnet 
  5. .DESCRIPTION 
  6.     This script uses SMO to Find all the local SQL Servers  
  7.     and displays them 
  8.  
  9. .NOTES 
  10.     File Name  : Get-SQLServer2.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 3.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16. .EXAMPLE 
  17.     PS>  # On a Lync Server looking at Lync Implementation 
  18.     PS>  Get-SQLServer2 
  19.     There are 7 SQL Server(s) on the Local Subnet 
  20.  
  21.     ServerName      InstanceName Version      
  22.     ----------      ------------ -------      
  23.     2013-LYNC-MGT   MON          10.50.2500.0 
  24.     2013-LYNC-MGT   SCOM         10.50.2500.0 
  25.     2013-TS         RTCLOCAL     11.0.2100.60 
  26.     2013-SHAREPOINT SPSDB        11.0.3000.0  
  27.     2013-LYNC-FE    RTC          11.0.2100.60 
  28.     2013-LYNC-FE    RTCLOCAL     11.0.2100.60 
  29.     2013-LYNC-FE    LYNCLOCAL    11.0.2100.60 
  30.      
  31. #> 
  32. Import-Module SQLPS 
  33.  
  34. # Now get all the database servers on the local subnet 
  35.  
  36. $SQLservers = [System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources() 
  37. $Srvs= @() 
  38.  
  39. # Convert collection to an array 
  40. Foreach ($srv in $SQLservers) { 
  41. $srvs += $srv 
  42. } 
  43.  
  44. # Now display results 
  45. If ($Srvs.count -LE 0) { 
  46. "There are no SQL Servers on the Local Subnet" 
  47. return
  48. } 
  49.  
  50. # Now print server details 
  51. "There are {0} SQL Server(s) on the Local Subnet" -f $Srvs.count 
  52. $Srvs | Select ServerName, InstanceName, Version | Format-Table -AutoSize 

Saturday, 12 October 2013

Get-OLCalendarItem

  1. Function Get-OLCalendarItem { 
  2.  
  3.  
  4. <# 
  5. .SYNOPSIS 
  6.     A function to retreive Outlook Calender items between two dates.  
  7.     Returns PSobjects containing each item. 
  8. .DESCRIPTION 
  9.     The function opens one's outlook calender, then retrieves the items.  
  10.     The function takes 2 parameter: start, end - items are returned that  
  11.     start betweween these two dates. 
  12. .NOTES 
  13.     File Name  : Get-OLCalendarItem 
  14.     Author     : Thomas Lee - tfl@psp.co.uk 
  15.     Requires   : PowerShell Version 3.0 
  16. .LINK 
  17.     This script posted to: 
  18.         http://www.pshscripts.blogspot.com 
  19.      
  20. .EXAMPLE 
  21.     Left as an exercise for the reader      
  22.  
  23. #> 
  24.  
  25. [CmdletBinding()] 
  26. Param ( 
  27. $start = $(Get-Date) , 
  28. $end   = $((Get-date).AddMonths(1)) 
  29. ) 
  30.  
  31. Write-Verbose "Returning objects between: $($start.tostring()) and $($end.tostring())" 
  32. # Load Outlook interop and Outlook iteslf 
  33. [Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Outlook") | out-null 
  34. $Outlook = new-object -comobject outlook.application 
  35.  
  36. # Get OL default folders 
  37. $OlFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type] 
  38. $Namespace = $Outlook.GetNameSpace("MAPI") 
  39. $Calendar = $namespace.GetDefaultFolder($olFolders::olFolderCalendar) 
  40. Write-Verbose "There are $($calendar.items.count) items in the calender in total" 
  41.  
  42. # Now return psobjects for all items between 2 dates 
  43. ForEach ($citem in ($Calendar.Items | sort start)) { 
  44. #Write-Verbose "Processing [$($citem.Subject)]  Starting: [$($Citem.Start)]" 
  45.  
  46. If ($citem.start -ge $start -and $citem.start -LE $end) {  
  47.  
  48. $CalHT =[ordered]  @{ 
  49. Subject          =  $($Citem.Subject) 
  50. Location         =  $($Citem.Location); 
  51. Start            =  $(Get-Date $Citem.Start); 
  52. StartUTC         =  $(Get-Date $Citem.StartUTC);                                   
  53. End              =  $(Get-Date $Citem.End); 
  54. EndUTC           =  $(Get-Date $Citem.EndUTC); 
  55. Duration         =  $($Citem.Duration); 
  56. Importance       =  $($Citem.Importance); 
  57. IsRecurring      =  $($Citem.IsRecurring); 
  58. AllDayEvent      =  $($citem.AllDayEvent); 
  59. Sensitivity      =  $($Citem.Sensitivity); 
  60. ReminderSet      =  $($Citem.ReminderSet); 
  61. CreationTime     =  $($Citem.CreationTime); 
  62. LastModificationTime = $($Citem.LastModificationTime); 
  63. Body             =  $($Citem.Body); 
  64. } 
  65.  
  66.  
  67. # Write the item out as a custom item 
  68. $o=New-Object PSobject -Property $CalHT 
  69. Write-Output $o 
  70.  
  71. } 
  72. } #End of foreach 
  73.  
  74. }  # End of function 
  75.  
  76. Set-Alias GCALI Get-OLCalendarItem  
Technorati Tags: ,