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. # Now display results 
  44. If ($Srvs.count -LE 0) { 
  45. "There are no SQL Servers on the Local Subnet" 
  46. return
  47.  
  48. # Now print server details 
  49. "There are {0} SQL Server(s) on the Local Subnet" -f $Srvs.count 
  50. $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. Write-Verbose "Returning objects between: $($start.tostring()) and $($end.tostring())" 
  31. # Load Outlook interop and Outlook iteslf 
  32. [Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Outlook") | out-null 
  33. $Outlook = new-object -comobject outlook.application 
  34.  
  35. # Get OL default folders 
  36. $OlFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type] 
  37. $Namespace = $Outlook.GetNameSpace("MAPI"
  38. $Calendar = $namespace.GetDefaultFolder($olFolders::olFolderCalendar) 
  39. Write-Verbose "There are $($calendar.items.count) items in the calender in total" 
  40.  
  41. # Now return psobjects for all items between 2 dates 
  42. ForEach ($citem in ($Calendar.Items | sort start)) { 
  43. #Write-Verbose "Processing [$($citem.Subject)]  Starting: [$($Citem.Start)]" 
  44.  
  45. If ($citem.start -ge $start -and $citem.start -LE $end) {  
  46.  
  47. $CalHT =[ordered]  @{ 
  48. Subject          =  $($Citem.Subject) 
  49. Location         =  $($Citem.Location); 
  50. Start            =  $(Get-Date $Citem.Start); 
  51. StartUTC         =  $(Get-Date $Citem.StartUTC);                                   
  52. End              =  $(Get-Date $Citem.End); 
  53. EndUTC           =  $(Get-Date $Citem.EndUTC); 
  54. Duration         =  $($Citem.Duration); 
  55. Importance       =  $($Citem.Importance); 
  56. IsRecurring      =  $($Citem.IsRecurring); 
  57. AllDayEvent      =  $($citem.AllDayEvent); 
  58. Sensitivity      =  $($Citem.Sensitivity); 
  59. ReminderSet      =  $($Citem.ReminderSet); 
  60. CreationTime     =  $($Citem.CreationTime); 
  61. LastModificationTime = $($Citem.LastModificationTime); 
  62. Body             =  $($Citem.Body); 
  63.  
  64.  
  65. # Write the item out as a custom item 
  66. $o=New-Object PSobject -Property $CalHT 
  67. Write-Output $o 
  68.  
  69. } #End of foreach 
  70.  
  71. }  # End of function 
  72.  
  73. Set-Alias GCALI Get-OLCalendarItem  
Technorati Tags: ,