forked from MikeFal/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.ps1
60 lines (46 loc) · 2.02 KB
/
profile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#load SMO library
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
function Get-FreeSpace{
<#
.SYNOPSIS
Uses WMI to get capacity and freespace for all disks/mounts on a host.
.DESCRIPTION
Uses WMI Win32_Volume to query logical disks and provide drive size and usage for all
logical disks and mountpoints. If no parameter is given, localhost is used. Otherwise
the host name should be passed.
Mike Fal (http://www.mikefal.net) 2012-10-10
.PARAMETER
String
host - Name of machine information is being queried from, defaults to localhost
.EXAMPLE
Get-FreeSpace "CCX-SQL-PRD-01"
#>
param([string] $hostname = ($env:COMPUTERNAME))
gwmi win32_volume -computername $hostname | where {$_.drivetype -eq 3} | Sort-Object name `
| ft name,@{l="Size(GB)";e={($_.capacity/1gb).ToString("F2")}},@{l="Free Space(GB)";e={($_.freespace/1gb).ToString("F2")}},@{l="% Free";e={(($_.Freespace/$_.Capacity)*100).ToString("F2")}}
}
function Test-SQLConnection{
param([parameter(mandatory=$true)][string] $InstanceName)
$smosrv = new-object ('Microsoft.SqlServer.Management.Smo.Server') $InstanceName
$return = New-Object –TypeName PSObject –Prop @{'InstanceName'=$InstanceName;'StartupTime'=$null}
try{
$check=$smosrv.Databases['tempdb'].ExecuteWithResults('SELECT @@SERVERNAME')
$return.InstanceName = $smosrv.Name
$return.StartupTime = $smosrv.Databases['tempdb'].CreateDate
}
catch{
#do nothing on the catch
}
return $return
}
function Test-SQLAGRole{
param([parameter(mandatory=$true,ValueFromPipeline=$true)][string] $ComputerName)
If(Test-SQLConnection -ComputerName $computerName){
$smosrv = new-object ('Microsoft.SqlServer.Management.Smo.Server') $ComputerName
if($smosrv.AvailabilityGroups[0].PrimaryReplicaServerName -eq $smosrv.ComputerNamePhysicalNetBIOS){return "Primary"}
else{"Secondary"}
}
else{
return "Unreachable"
}
}