Skip to content

Commit 5028786

Browse files
mergestuff
2 parents 89c9029 + daac247 commit 5028786

5 files changed

+381
-284
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Get the Pools
2+
$Pools = Get-SCStaticIPAddressPool -VMMServer $VMMServer | Where {$_.Name -in @('VMPool', 'ListenerPool', 'ClusterPool') -and $_.LogicalNetworkDefinition -like '*LS*'}
3+
4+
$Answer = foreach ($pool in $Pools) {
5+
$Name = $pool.Name
6+
Write-PSFMessage "Working on Pool - $Name " -Verbose
7+
# split them up to get the base and the4 last octet
8+
$StartIp = [IPAddress]$pool.IPAddressRangeStart
9+
$StartIpLastOctet = $StartIp.GetAddressBytes()[-1]
10+
$NetworkBase = $StartIp.GetAddressBytes()[0..2] -join "."
11+
12+
$EndIP = [IPAddress]$pool.IPAddressRangeEnd
13+
$EndIPLastOctet = $EndIP.GetAddressBytes()[-1]
14+
15+
$DNSRecords = Get-WmiObject -Class MicrosoftDNS_AType -NameSpace Root\MicrosoftDNS -ComputerName 10.202.31.30 -Filter "DomainName = 'ls1test.local'" | Select-Object -property Ownername, ipaddress
16+
17+
18+
$IP = $StartIpLastOctet
19+
#loop through them
20+
While ($IP -le $EndIPLastOctet) {
21+
$IPAddress = $NetworkBase + "." + $IP
22+
Write-PSFMessage "Working on IPADdress $IPAddress" -Verbose
23+
try {
24+
$resolves = Resolve-DnsName $IPAddress -ErrorAction Stop
25+
$Resolved = $true
26+
$VMName = $resolves.NameHost
27+
switch ($Name) {
28+
VMPool {
29+
if ($VMName -like '*VM*') {
30+
$ISDba = $true
31+
}
32+
else {
33+
$ISDba = $False
34+
}
35+
}
36+
ListenerPool {
37+
if ($VMName -like '*DB*') {
38+
$ISDba = $true
39+
}
40+
else {
41+
$ISDba = $False
42+
}
43+
}
44+
ClusterPool {
45+
$ISDba = $False
46+
}
47+
Default {}
48+
}
49+
}
50+
catch {
51+
<#
52+
if ($Name -eq 'ClusterPool') {
53+
Write-PSFMessage "Trying IPADdress $IPAddress as Cluster" -Verbose
54+
try {
55+
$resolves = Resolve-DnsName (Get-Cluster $IPAddress -ErrorAction Stop).Name -ErrorAction Stop
56+
$Resolved = $true
57+
$VMName = $resolves.Name
58+
if ($VMName -like '*CLU*') {
59+
$ISDba = $true
60+
}
61+
else {
62+
$ISDba = $False
63+
}
64+
}
65+
Catch {
66+
$Resolved = $false
67+
$VMName = 'Nobody Knows'
68+
}
69+
}#>
70+
71+
if($Name -eq 'ListenerPool' -or $Name -eq 'ClusterPool'){
72+
Write-PSFMessage "Trying IPADdress $IPAddress" -Verbose
73+
if($IPaddress -in $DNSRecords.IPADdress){
74+
$VMName = $DNSRecords.Where{$_.IpAddress -eq $IPAddress}.OwnerName -Join " "
75+
if ($VMName -like '*DB*' -or $VMName -like '*CLU*') {
76+
$ISDba = $true
77+
}
78+
else {
79+
$ISDba = $False
80+
}
81+
}
82+
}
83+
else {
84+
$Resolved = $false
85+
$VMName = 'Nobody Knows'
86+
}
87+
}
88+
89+
[PSCustomObject]@{
90+
PoolName = $Name
91+
IPAddress = $IPAddress
92+
Resolved = $Resolved
93+
IsDBA = $ISDba
94+
VMName = $VMName
95+
}
96+
Write-PSFMessage "Finished IPADdress $IPAddress" -Verbose
97+
98+
$IP ++
99+
}
100+
101+
}
102+

Convert-ADSPowerShellForMarkdown.ps1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
function Convert-ADSPowerShellForMarkdown {
3+
<#
4+
.SYNOPSIS
5+
Converts PowerShell code into valid Markdown URI Link text
6+
7+
.DESCRIPTION
8+
Converts PowerShell code into valid Markdown URI Link Text
9+
10+
.PARAMETER inputstring
11+
The endoded URL from the website
12+
13+
.PARAMETER LinkText
14+
The text to show for the link
15+
16+
.PARAMETER ToClipBoard
17+
Will not output to screen but instead will set the clipboard
18+
19+
.EXAMPLE
20+
Convert-ADSPowerShellForMarkdown if+%28-not+%28%24IsLinux+-or+%24IsMacOS%29+%29+%7B%0D%0A++++if+%28-not%28Test-Path+C%3A%5C%5CMSSQL%5C%5CBACKUP%29%29+%7B%0D%0A++++++++Write-Output+%22I%27m+going+to+create+C%3A%5C%5CMSSQL%5C%5CBACKUPS+so+that+the+docker-compose+will+work%22%0D%0A++++++++New-Item+C%3A%5CMSSQL1%5CBACKUP1+-ItemType+Directory%0D%0A++++%7D%0D%0A++++else+%7B%0D%0A++++++++Write-Output+%22C%3A%5C%5CMSSQL%5C%5CBACKUPS+already+exists%22%0D%0A++++%7D%0D%0A%7D%0D%0Aelse+%7B%0D%0A++++Write-Warning+%22Sorry+This+code+won%27t+run+on+Linux+-+You+will+have+to+do+it+manually+and+edit+the+docker+compose+file%22%0D%0A%7D -ToClipBoard
21+
22+
Converts the encoded URL so that it works with MarkDown and sets it to the clipboard
23+
24+
.NOTES
25+
June 2019 - Rob Sewell @SQLDbaWithBeard
26+
SQLDBAWithABeard.Com
27+
#>
28+
29+
Param(
30+
[Parameter(Mandatory = $true)]
31+
[string]$inputstring,
32+
[string]$linktext = " LINK TEXT HERE ",
33+
[switch]$ToClipBoard
34+
)
35+
clear
36+
[Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
37+
$encodedstring = [System.Web.HttpUtility]::UrlEncode($inputstring)
38+
$linkage = $encodedstring.Replace('+', ' ').Replace('%3a', ':').Replace('%5c', '%5c%5c').Replace('%22', '\u0022').Replace('%27', '\u0027').Replace('%0D%0A', '').Replace('%3b%0a','\u003B ').Replace('%0a','\u000A')
39+
40+
$outputstring = @"
41+
<a href="command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22 $linkage \u000D %22%7D">$linktext</a>
42+
"@
43+
if ($ToClipBoard) {
44+
if (-not ($IsLinux -or $IsMacOS) ) {
45+
$outputstring | Set-Clipboard
46+
}
47+
else {
48+
Write-Warning "Set-Clipboard - Doesnt work on Linux - Outputting to screen"
49+
$outputstring
50+
}
51+
}
52+
else {
53+
$outputstring
54+
}
55+
}

0 commit comments

Comments
 (0)