-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.ps1
More file actions
43 lines (36 loc) · 1.93 KB
/
script.ps1
File metadata and controls
43 lines (36 loc) · 1.93 KB
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
$diskNum = 2 # The disk number to check
$chkdskCmd = "/x" # /x is faser, /r is more detailed
$diskLetter = "L:"
If (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host 'Not running as admin, cant pereform checks' -ForegroundColor Red
} Else {
if (-Not (Test-Path -Path "$PSScriptRoot\log\")) {
New-Item -Path "$PSScriptRoot" -Name "log" -ItemType "Directory"
}
$running = $true
while ($running) {
Write-Host "running as admin"
Write-Host "Changing disk number in files"
$file = Get-Content -Path "$PSScriptRoot\diskpartCmdsOFF.txt"
$file[0] = "select disk $diskNum"
Set-Content -Path "$PSScriptRoot\diskpartCmdsOFF.txt" -Value $file
$file = Get-Content -Path "$PSScriptRoot\diskpartCmdsON.txt"
$file[0] = "select disk $diskNum"
Set-Content -Path "$PSScriptRoot\diskpartCmdsON.txt" -Value $file
$srlNum = Get-Disk -Number $diskNum | Select-Object SerialNumber, OperationalStatus
$filePath = $PSScriptRoot + "\log\" + $srlNum.SerialNumber + ".txt"
if ($srlNum.OperationalStatus.toString() -eq "Offline") {
Write-Host "Setting disk online"
diskpart /s "$PSScriptRoot\diskpartCmdsOFF.txt" | Out-File -FilePath $filePath
}
Write-Host "Running diskpart commands"
diskpart /s "$PSScriptRoot\diskpartCmdsON.txt" | Out-File -FilePath $filePath
Write-Host "Running check disk command with $chkdskCmd"
chkdsk $chkdskCmd $diskLetter | Out-File -FilePath $filePath
Write-Host "Successfully ran all commands, check log dir to output"
$runAgain = Read-Host "Press ENTER to continue. EXIT to quit"
if ($runAgain.ToString().ToLower() -eq "exit") {
$running = $false
}
}
}