Connecting to Office 365 with PowerShell

This is just s simple script for connecting to Office 365 with PowerShell.


# Import Required PowerShell Modules
# Note - the Script Requires PowerShell 3.0!

Import-Module MSOnline 

# Office 365 Admin Credentials
$CloudUsername = 'username'
$CloudPassword = ConvertTo-SecureString 'password' -AsPlainText -Force
$CloudCred = New-Object System.Management.Automation.PSCredential $CloudUsername, $CloudPassword 

# Connect to Office 365
Connect-MsolService -Credential $CloudCred

Advertisement

Windows PowerShell 3.0 and Server Manager Quick Reference Guides

Microsoft has released some quick reference guides from PowerShell Magazine ; see http://www.microsoft.com/en-us/download/details.aspx?id=30002 for more information.

Quickly learn tips, shortcuts, and common operations in the new Windows Powershell 3.0, Windows PowerShell Workflow, Windows PowerShell ISE, Windows PowerShell Web Access, Server Manager for Windows Server 2012 Release Candidate, WinRM, WMI, and WS-Man.

PowerShell_LangRef_v3.pdf – This four-page reference describes operators, arrays, useful commands, methods, and other tips for using Windows PowerShell 3.0. Also included is a Windows PowerShell reading and tutorial resource list. This quick reference is provided by PowerShell Magazine.

PowerShell_ISE_v3.pdf – This two-page reference describes keyboard shortcuts and hotkeys that you can use to navigate Windows PowerShell Integrated Scripting Environment (ISE) more quickly, and introduces the new ISE object model. Also included are tips for configuring $ps.ISE options, profiles, and properties. This quick reference is provided by PowerShell Magazine.

PowerShell_Examples_v3.pdf – This two-page reference describes how to perform popular IT management and scripting tasks by using Windows PowerShell 3.0, including how to fetch data by using Management OData IIS Services, how to schedule jobs, how to install Windows PowerShell Web Access by using Windows PowerShell cmdlets, and how to create new SMB file shares. This quick reference is provided by PowerShell Magazine.

Quick_Reference_SM_WS12.pdf – This two-page reference describes common tasks that you can perform in the new Server Manager console in Windows Server 2012 Release Candidate. Quickly learn how to manage remote servers that are running older versions of Windows Server by using the new Server Manager; how to run Server Manager deployment cmdlets for Windows PowerShell; how to save and export Server Manager settings, such as the servers you have added to the server pool, and custom server groups that you have created; where to find Server Manager log files; how to run popular WinRM commands such as creating a new listener; how to install roles and features on offline VHDs; and where to find documentation to help you manage multiple, remote servers by using Server Manager and Windows PowerShell.

WMI_CIM_PowerShell_v3.pdf – This two-page reference describes differences between Windows Management Instrumentation (WMI) in Windows PowerShell 2.0 and 3.0. Included are examples of how to find namespaces and classes in WMI, detailed information about CimSession, CimInstance, CIM operations, and invoking a CIM method. The quick reference describes how to get a list of new CIM cmdlets, and defines associations, WQL, WS-Man, WinRM, and CIM indications.

SQL 2012 PowerShell script to detect CPU’s configured for licensing

SQL 2012 has changed the license model around CPUs/Cores. The below script can be used to help detect how many CPU’s are on the host and also configured in SQL. If you detect that you do not have the correct CPU’s, then you may need to reconfigure SQL.

Example outputs:

SQL Server CPU check
Checking server instance TESTSQL
—————————————————
Server Physical Cores : 4 ( 2399 mhz )
Server Logical Cores  : 4
SQL Server Cores      : 4
SQL Edition           : Standard Edition (64-bit)
—————————————————

SQL Server CPU check
Checking server instance TESTSQL
—————————————————
Server Physical Cores : 4 ( 2399 mhz )
Server Logical Cores  : 4
SQL Server Cores      : 2
SQL Edition           : Standard Edition (64-bit)
—————————————————

Script:

################################################################################
#
# Script: DetectCPUCores.ps1
#
# Author: Craig Wilson
# Date: 22/06/2012
# Version: v1.0.0
#
# This script will connect SQL and the WMI of then host to collect CPU core
# information
################################################################################

function DetectCPUCores ([string]$SQLINSTANCE, [string]$HOSTNAME)
{

    Write-Host "SQL Server CPU check"
    Write-Host " Checking server instance $SQLINSTANCE"
    Write-Host "---------------------------------------------------"    

    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection 
    $SqlConnection.ConnectionString = "Data Source=$SQLINSTANCE;Integrated Security=TRUE" 
    $SqlConnection.Open() 

    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand 
    $SqlCmd.CommandText = "select serverproperty('ProductVersion')" 
    $SqlCmd.Connection = $SqlConnection 
    $sql_ProductVersion = $SqlCmd.ExecuteScalar() 

    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand 
    $SqlCmd.CommandText = "select serverproperty('Edition')" 
    $SqlCmd.Connection = $SqlConnection 
    $sql_edition = $SqlCmd.ExecuteScalar() 

    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand 
    $SqlCmd.CommandText = "select count(*) from sys.dm_os_schedulers where status = 'VISIBLE ONLINE'" 
    $SqlCmd.Connection = $SqlConnection 
    $sql_schedulers = $SqlCmd.ExecuteScalar() 

    $SqlConnection.Close() 

    $property = "systemname","maxclockspeed","addressWidth","numberOfCores", "NumberOfLogicalProcessors"
    $cpu_info = Get-WmiObject -computername $HOSTNAME -class win32_processor -Property  $property | Select-Object -Property $property 

    Write-Host "Server Physical Cores :"$cpu_info.numberOfCores "("$cpu_info.maxclockspeed"mhz ) "
    Write-Host "Server Logical Cores :"$cpu_info.NumberOfLogicalProcessors
    Write-Host "SQL Server Cores : $sql_schedulers"
    Write-Host "SQL Edition : $sql_edition"
    Write-Host "SQL Product Version : $sql_ProductVersion"
    Write-Host "---------------------------------------------------"

}

DetectCPUCores "SQLInstance" "LOCALHOST"



For more information on how the licensing impact you check out the following blog posts

SQL Server 2012 Enterprise Editions

http://blogs.msdn.com/b/saponsqlserver/archive/2012/06/15/sql-server-2012-enterprise-editions.aspx

SQL Server 2012 Licensing (Resources Pane)

http://www.microsoft.com/sqlserver/en/us/get-sql-server/licensing.aspx