-
Notifications
You must be signed in to change notification settings - Fork 1
/
pre-postMigration.ps1
207 lines (152 loc) · 8.49 KB
/
pre-postMigration.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# variable assignment
# use below arguemnt
$argMigrationStage = $args[0]
$logLocationInput = $(Get-Location) # this location when using az cli invoke command will position file in "c:\azure"
$instanceName = $env:computername
$bootType = $env:firmware_type
$osVersion = $(Get-WmiObject -class Win32_OperatingSystem).caption
#$guidGen = $([guid]::NewGuid().ToString())
#$guidGenShort = $guidGen.substring(0,8)
$dateTimeStamp = $(Get-Date -Format "dd-MM-yyyy" )
# Define log location
$logLocation = New-Item -Path $logLocationInput -Name "$argMigrationStage-$instanceName-$dateTimeStamp.log" -ItemType "file" -Value ""
# computername stamp
Write-Output "Computer Name: $instanceName" | Out-File -Append $logLocation
Write-Output "" | Out-File -Append $logLocation
Write-Output "$osVersion" | Out-File -Append $logLocation
# Fetch Domain Name (FQDN)
$fqdn = ([System.Net.Dns]::GetHostByName(($env:computerName))).Hostname
Write-Output "" | Out-File -Append $logLocation
Write-Output "FQDN: $fqdn" | Out-File -Append $logLocation
# get boot type e.g. bios(legacy) or UEFI
Write-output "Boot Type" | Out-File -Append $logLocation
Write-output $bootType | Out-File -Append $logLocation
Write-Output "" | Out-File -Append $logLocation
# fetch RAM
$totalMemory = Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum | Foreach {"{0:N2}" -f ([math]::round(($_.Sum / 1GB),2))}
Write-Output "RAM: $totalMemory GB" | Out-File -Append $logLocation
# fetch vCPU
$vcpu = (Get-CimInstance -ClassName 'Win32_Processor' | Measure-Object -Property 'NumberOfCores' -Sum).Sum
Write-Output "vCPUs: $vcpu" | Out-File -Append $logLocation
# check if vmstorfl.sys exists - required for ASR to migrate VM's
If (Test-Path -Path C:\Windows\system32\drivers\vmstorfl.sys) {
Write-Output "vmstorfl.sys exists" | Out-File $logLocation -append
}
else{
Write-Output "vmstorfl.sys doesn't exists" | Out-File $logLocation -append
}
# add a copy nested else statement to create dummy file: "copy nul c:\Windows\system32\drivers\vmstorfl.sys"
Write-Output "" | Out-File -Append $logLocation
# last reboot checker greater or equal to 30 days
$Today = Get-Date
$lastReboot = Get-WmiObject win32_operatingsystem | Select-Object csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
$diffCheck = $Today.date - $lastReboot.lastbootuptime.date
if ($diffCheck.TotalDays -ge 30 ){
Write-Output "Instance has not been rebooted for 30 days +" | Out-File $logLocation -append
}
else{
Write-Output 'Last reboot in days:' $diffCheck.TotalDays | Out-File $logLocation -append
}
Write-Output "" | Out-File -Append $logLocation
# san policy checker - online all
$sanpolicy = "san" | diskpart
"exit" | diskpart
if ($sanpolicy | Select-String "Online All") {
Write-Output "San Policy is Online All" | Out-File -Append $logLocation
}
else {
Write-Output "San Policy is not online" | Out-File -Append $logLocation
}
# boot disk checker
$bootchecker = "list disk" | diskpart
"exit" | diskpart
Write-Output $bootchecker | Out-File -Append $logLocation
# fetch disk info
$logicaldisks = Get-WmiObject Win32_Logicaldisk | Select-Object SystemName,DeviceID,@{Name="size(GB)"; Expression={[math]::round($_.size/1GB)}} | Format-Table -AutoSize | Out-File $logLocation -append
# fetch drive letters and output physical and logic sector sizes for each drive
$driveLetters = Get-PSDrive | Select-Object -ExpandProperty 'Name' | Select-String -Pattern '^[a-z]$'
foreach($i in $driveLetters) {Write-Output "Drive Letter: $i"; Write-output ""; fsutil fsinfo ntfsinfo $i":"; Write-output "" | select-string "Sector" | Out-File $logLocation -append}
# Check if there is disk encryption
$BLockerCheck = manage-bde -status
if (-Not($BLockerCheck | Select-String "Protection On")) {
Write-Output "Bitlocker is not enabled - no disks encrypted." | Out-File -Append $logLocation
} Else {
Write-Output "Bitlocker is enabled - potential disks encrypted." | Out-File -Append $logLocation
}
Write-Output "" | Out-File -Append $logLocation
# fetch network properties
$networkProperties = (Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object InterfaceAlias, AddressFamily, ServerAddresses)
Write-Output $networkProperties | Out-File -Append $logLocation
# fetch networking related info
$ipAddressBound = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' | Select-Object -ExpandProperty IPAddress | Where-Object { $_ -match '(\d{1,3}\.){3}\d{1,3}' } | Out-File $logLocation -append
$ConnectedNics = Get-WmiObject win32_networkadapter -filter "netconnectionstatus = 2" | Measure-Object
$NicsList = $ConnectedNics | Select-Object netconnectionid, name | Out-String
$NicsCount = $ConnectedNics.Count
Write-Output "Total Nics: $nicsCount" | Out-File -Append $logLocation
Write-Output "" | Out-File -Append $logLocation
# fetch total disk size
$diskCapacity = Get-WmiObject Win32_LogicalDisk | Select-Object DeviceID, @{'Name' = 'Total Disk Size (GB)'; Expression= { ($_.Size) / 1GB }}
Write-Output $diskCapacity | Out-File -Append $logLocation
# fetch used disk space
$usedSpace = Get-WmiObject Win32_LogicalDisk | Select-Object DeviceID, @{'Name' = 'Used Disk Space (GB)'; Expression= { ($_.Size - $_.FreeSpace) / 1GB }}
Write-Output $usedSpace | Out-File -Append $logLocation
# fetch Disk Model - VMDK or NetApp iSCSI
$diskModel = (Get-WmiObject Win32_DiskDrive | ForEach-Object {
$disk = $_
$partitions = "ASSOCIATORS OF " +
"{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
"WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Get-WmiObject -Query $partitions | ForEach-Object {
$partition = $_
$drives = "ASSOCIATORS OF " +
"{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
"WHERE AssocClass = Win32_LogicalDiskToPartition"
Get-WmiObject -Query $drives | ForEach-Object {
New-Object -Type PSCustomObject -Property @{
DiskModel = $disk.Model
DriveLetter = $_.DeviceID
VolumeName = $_.VolumeName
}
}
}
})
Write-Output $diskModel | Out-File -Append $logLocation
# fetch free disk space
$usedSpace = Get-WmiObject Win32_LogicalDisk | Select-Object DeviceID, @{'Name' = 'Free Disk Space (GB)'; Expression= { ($_.FreeSpace) / 1GB }}
Write-Output $usedSpace | Out-File -Append $logLocation
# fetch dns addresses
$dnsNetworks = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ErrorAction Stop
foreach($dnsNetwork in $dnsNetworks) {
$DNSServers = $dnsNetwork.DNSServerSearchOrder
$dnsNetworkName = $dnsNetwork.Description
If(!$DNSServers) {
$PrimaryDNSServer = "Notset"
$SecondaryDNSServer = "Notset"
} elseif($DNSServers.count -eq 1) {
$PrimaryDNSServer = $DNSServers[0]
$SecondaryDNSServer = "Notset"
} else {
$PrimaryDNSServer = $DNSServers[0]
$SecondaryDNSServer = $DNSServers[1]
}
If($dnsNetwork.DHCPEnabled) {
$IsDHCPEnabled = $true
}
$OutputObj = New-Object -Type PSObject
$OutputObj | Add-Member -MemberType NoteProperty -Name PrimaryDNSServers -Value $PrimaryDNSServer
$OutputObj | Add-Member -MemberType NoteProperty -Name SecondaryDNSServers -Value $SecondaryDNSServer
$OutputObj | Add-Member -MemberType NoteProperty -Name IsDHCPEnabled -Value $IsDHCPEnabled
}
$OutputObj | Out-File -Append $logLocation
$gatewayAddress = $(Get-WmiObject -Class Win32_IP4RouteTable | where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0'} | select-object -ExpandProperty nexthop)
$gatewayCheck = $(Test-Connection (Get-WmiObject -Class Win32_IP4RouteTable | where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0'} | select-object -ExpandProperty nexthop) -Quiet -Count 1)
if ($gatewayCheck -eq "True"){
Write-Output "Gateway Reachable - $gatewayAddress" | Out-File -Append $logLocation
}
else{
Write-Output "Gateway Unreachable - $gatewayAddress" | Out-File -Append $logLocation
}
# Get .NET Framework versions installed
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version | out-file $logLocation -append
# fetch running services
$RunningServices = Get-Service | Where-Object {$_.Status -eq "Running"} | Select-Object status, name| Out-File $logLocation -append