Skip to content

Commit

Permalink
New tools added
Browse files Browse the repository at this point in the history
  • Loading branch information
DeploymentBunny committed Nov 16, 2016
1 parent f3ad624 commit 53c912d
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
'// Version: 2.2 - Dec 28 2015
'// Version: 2.3 - Jan 24 2016
'// Version: 2.4 - Feb 8 2016
'// Version: 2.5 - Nov 11 2016 - Moved the DISM section /Resetbase for 10. Minor updates in remarks and text

'// Mikael Nystrom & Johan Arwidmark
'// This script is provided "AS IS" with no warranties, confers no rights and
'// is not supported by the authors, Deployment Bunny or Deployment Artists.
Expand Down Expand Up @@ -320,17 +322,6 @@ Function ZTIProcess()
ZTIProcess = Failure
End If

'Execute DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
oLogging.CreateEntry sActionName & ": Running DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase", LogTypeInfo
iRetVal = oUtility.RunWithConsoleLogging("DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase")
oLogging.CreateEntry sActionName & ": Done", LogTypeInfo

if (iRetVal = 0) or (iRetVal = 3010) then
ZTIProcess = Success
Else
ZTIProcess = Failure
End If

'Execute CleanMgr.exe /sagerun:5432
oLogging.CreateEntry sActionName & ": Running CleanMgr.exe /sagerun:5432", LogTypeInfo
iRetVal = oUtility.RunWithConsoleLogging("CleanMgr.exe /sagerun:5432")
Expand All @@ -350,7 +341,18 @@ Function ZTIProcess()
oLogging.CreateEntry sActionName & ": Done", LogTypeInfo
oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
oLogging.CreateEntry oUtility.ScriptName & ": Finished", LogTypeInfo


'Execute DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
oLogging.CreateEntry sActionName & ": Running DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase", LogTypeInfo
iRetVal = oUtility.RunWithConsoleLogging("DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase")
oLogging.CreateEntry sActionName & ": Done", LogTypeInfo

if (iRetVal = 0) or (iRetVal = 3010) then
ZTIProcess = Success
Else
ZTIProcess = Failure
End If

End Select
Case "True"
'Server OS
Expand Down Expand Up @@ -504,7 +506,7 @@ Function ZTIProcess()
oLogging.CreateEntry oUtility.ScriptName & ": Finished", LogTypeInfo

Case "10."
' Windows Server "10"
' Windows Server 2016
oLogging.CreateEntry sActionName & ": Running on Windows Server Technical Preview", LogTypeInfo

'Execute DISM.exe /online /Cleanup-Image /RestoreHealth
Expand All @@ -517,6 +519,15 @@ Function ZTIProcess()
Else
ZTIProcess = Failure
End If

'Cleaning up the SoftwareDistribution folder
oLogging.CreateEntry sActionName & ": Cleaning up the SoftwareDistribution folder", LogTypeInfo
oUtility.RunWithConsoleLogging("net.exe stop wuauserv")
oUtility.RunWithConsoleLogging("cmd.exe /c del c:\windows\SoftwareDistribution /q /s")
oUtility.RunWithConsoleLogging("net.exe start wuauserv")
oLogging.CreateEntry sActionName & ": Done", LogTypeInfo
oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
oLogging.CreateEntry oUtility.ScriptName & ": Finished", LogTypeInfo

'Execute DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
oLogging.CreateEntry sActionName & ": Running DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase", LogTypeInfo
Expand All @@ -529,15 +540,6 @@ Function ZTIProcess()
ZTIProcess = Failure
End If

'Cleaning up the SoftwareDistribution folder
oLogging.CreateEntry sActionName & ": Cleaning up the SoftwareDistribution folder", LogTypeInfo
oUtility.RunWithConsoleLogging("net.exe stop wuauserv")
oUtility.RunWithConsoleLogging("cmd.exe /c del c:\windows\SoftwareDistribution /q /s")
oUtility.RunWithConsoleLogging("net.exe start wuauserv")
oLogging.CreateEntry sActionName & ": Done", LogTypeInfo
oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
oLogging.CreateEntry oUtility.ScriptName & ": Finished", LogTypeInfo

End Select

Case Else
Expand Down
65 changes: 65 additions & 0 deletions Tools/Get-ADHealthCheck/Get-ADHealthCheck.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<#
.Synopsis
Script from TechDays Sweden 2016
.DESCRIPTION
Script from TechDays Sweden 2016
.NOTES
Author - Mikael Nystrom
Twitter: @mikael_nystrom
Blog : http://deploymentbunny.com
Disclaimer:
This script is provided "AS IS" with no warranties, confers no rights and
is not supported by the authors or Deployment Artist.
.LINK
http://www.deploymentbunny.com
#>
$getForest = [system.directoryservices.activedirectory.Forest]::GetCurrentForest()
$DCServers = $getForest.domains | ForEach-Object {$_.DomainControllers} | ForEach-Object {$_.Name}

foreach ($DCServer in $DCServers){
Write-Host "Checking netaccess to $DCServer" -ForegroundColor Green
Test-NetConnection -ComputerName $DCServer

Write-Host "Checking Services that should be running on $DCServer" -ForegroundColor Green
Invoke-Command -ComputerName $DCServer -ScriptBlock {
$Services = Get-Service
Foreach($Service in $Services | Where-Object -Property StartType -EQ Automatic){
$Service | Where-Object -Property Status -NE -Value Running
}
}

Write-Host "Getting debug logs on $DCServer" -ForegroundColor Green
Invoke-Command -ComputerName $DCServer -ScriptBlock {
Write-Host "C:\Windows\debug\PASSWD.LOG on $DCServer says:" -ForegroundColor Green
Get-Content C:\Windows\debug\PASSWD.LOG
}

Write-Host "Getting debug logs on $DCServer" -ForegroundColor Green
Invoke-Command -ComputerName $DCServer -ScriptBlock {
Write-Host "C:\Windows\debug\netlogon.log on $DCServer says:" -ForegroundColor Green
Get-Content C:\Windows\debug\netlogon.log
}

Write-Host "Running DCDiag on $DCServer" -ForegroundColor Green
Invoke-Command -ComputerName $DCServer -ScriptBlock {
dcdiag.exe /test:netlogons /Q
dcdiag.exe /test:Services /Q
dcdiag.exe /test:Advertising /Q
dcdiag.exe /test:FSMOCheck /Q
}

Write-Host "Checking access to SYSVOL on $DCServer" -ForegroundColor Green
Test-Path -Path \\$DCServer\sysvol

Write-Host "Get 20 last errors/warning on $DCServer" -ForegroundColor Green
Invoke-Command -ComputerName $DCServer -ScriptBlock {
Get-EventLog -LogName Application -Newest 20 -EntryType Error,Warning | Select-Object Source,Message,TimeGenerated
}

Write-Host "Running BPA on $DCServer" -ForegroundColor Green
Invoke-Command -ComputerName $DCServer -ScriptBlock {
$BPA = "Microsoft/Windows/DirectoryServices"
Invoke-BpaModel -BestPracticesModelId $BPA
Get-BpaResult -ModelID $BPA -Filter Noncompliant | Select-Object ResultNumber,Severity,Category,Title,Problem,Impact,Resolution
}
}
49 changes: 49 additions & 0 deletions Tools/Get-DHCPHealthCheck/Get-DHCPHealthCheck.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<#
.Synopsis
Script from TechDays Sweden 2016
.DESCRIPTION
Script from TechDays Sweden 2016
.NOTES
Author - Mikael Nystrom
Twitter: @mikael_nystrom
Blog : http://deploymentbunny.com
Disclaimer:
This script is provided "AS IS" with no warranties, confers no rights and
is not supported by the authors or Deployment Artist.
.LINK
http://www.deploymentbunny.com
#>
$DHCPServers = "SRVDC01.network.local"
Foreach($DHCPServer in $DHCPServers){
Write-Host "Checking netaccess to $DCServer" -ForegroundColor Green
Test-Connection -ComputerName $DCServer


Invoke-Command -ComputerName $DCServer -ScriptBlock {
Write-Host "Getting other DCHP/PXE Servers from $env:COMPUTERNAME" -ForegroundColor Green
$DhcpServerInDCs = Get-DhcpServerInDC
$DhcpServerInDCs

Write-Host "Testing access to other DCHP/PXE Servers from $env:COMPUTERNAME" -ForegroundColor Green
Foreach($DhcpServerInDC in $DhcpServerInDCs){
Write-Host "Testing access to $($DhcpServerInDC.IPAddress)" -ForegroundColor Green
Test-NetConnection -ComputerName $DhcpServerInDC.IPAddress
}
}

Invoke-Command -ComputerName $DCServer -ScriptBlock {
Write-Host "Get all Scopes from $env:COMPUTERNAME" -ForegroundColor Green
$DhcpServerv4Scopes = Get-DhcpServerv4Scope
Foreach($DhcpServerv4Scope in $DhcpServerv4Scopes){
$DhcpServerv4Scope
Write-Host "Percent free $(($DhcpServerv4Scope | Get-DhcpServerv4ScopeStatistics).PercentageInUse) in $($DhcpServerv4Scope.scopeid)"
}
}

Write-Host "Running BPA on $DHCPServer" -ForegroundColor Green
Invoke-Command -ComputerName $DHCPServer -ScriptBlock {
$BPA = "Microsoft/Windows/DHCPServer"
Invoke-BpaModel -BestPracticesModelId $BPA
Get-BpaResult -ModelID $BPA -Filter Noncompliant | Select-Object ResultNumber,Severity,Category,Title,Problem,Impact,Resolution
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<#
.Synopsis
Script from TechDays Sweden 2016
.DESCRIPTION
Script from TechDays Sweden 2016
.NOTES
Author - Mikael Nystrom
Twitter: @mikael_nystrom
Blog : http://deploymentbunny.com
Disclaimer:
This script is provided "AS IS" with no warranties, confers no rights and
is not supported by the authors or Deployment Artist.
.LINK
http://www.deploymentbunny.com
#>
Function Get-RemoteComputerSystemInfo{
param(
$ComputerName
)

Invoke-Command -ComputerName $ComputerName -ScriptBlock {
Function Get-ComputerSystemInfo{
Write-Host "Getting data from $env:COMPUTERNAME"
$Index = Get-WmiObject -Class Win32_ReliabilityStabilityMetrics | Select-Object @{N="TimeGenerated"; E={$_.ConvertToDatetime($_.TimeGenerated)}},SystemStabilityIndex | Select-Object -First 1
$ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem
$OperatingSystem = Get-WmiObject -Class Win32_OperatingSystem | Select-Object @{N="LastBootUpTime"; E={$_.ConvertToDatetime($_.LastBootUpTime)}},Version
$Plupp = [ordered]@{
ComputerName = $($env:COMPUTERNAME)
Index = $([math]::Round($Index.SystemStabilityIndex))
TimeGenerated = $($Index.TimeGenerated)
Make = $($ComputerSystem.Manufacturer)
Model = $($ComputerSystem.Model)
OSVersion = $($OperatingSystem.Version)
UpTimeInDays = $([math]::round(((Get-Date) - ($OperatingSystem.LastBootUpTime)).TotalDays))
OSDiskFreeSpaceInGB = $([Math]::Round($(((Get-Volume -DriveLetter C).SizeRemaining)/1GB),2))
}
New-Object PSObject -Property $Plupp
}
Get-ComputerSystemInfo
}
}

#Get the servers
Write-Host "Getting Server names"
Import-Module "ActiveDirectory"
$Computers = Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(name=SRV*)(operatingSystem=Windows Server*)(!serviceprincipalname=*MSClusterVirtualServer*)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"

Write-Host "Found $($Computers.Count)"
Write-Host "Check if they are online"
$ComputersOnline = $Computers.DNShostname | Test-NetConnection -CommonTCPPort WINRM -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Where-Object -Property TcpTestSucceeded -EQ -Value True
Write-Host "Found $($ComputersOnline.Count) that seems to be online"

$TheSadTruth = Foreach($Computer in $ComputersOnline.ComputerName){
Get-RemoteComputerSystemInfo -ComputerName $Computer
}

$Title = "Cloud"
$Head = "Cloud"
$TheSadTruth | Sort-Object -Property ComputerName | ConvertTo-Html -As Table `
-Title $Title `
-Head $Head `
-Body (Get-Date -UFormat "%Y-%m-%d - %T ") `
-PreContent "<H3>Rel Index from $ENV:USERDNSDOMAIN</H3><P>Generated by Power of the Force</P>" `
-PostContent "<P>For details, contact [email protected].</P>" `
-Property ComputerName,Make,Model,OSVersion,OSDiskFreeSpaceInGB,UpTimeInDays,Index |
ForEach {
if($_ -like "*<td>10</td>*"){$_ -replace "<tr>", "<tr bgcolor=Lime>"}
elseif($_ -like "*<td>9</td>*"){$_ -replace "<tr>", "<tr bgcolor=Lime>"}
elseif($_ -like "*<td>8</td>*"){$_ -replace "<tr>", "<tr bgcolor=Lime>"}
elseif($_ -like "*<td>7</td>*"){$_ -replace "<tr>", "<tr bgcolor=Aqua>"}
elseif($_ -like "*<td>6</td>*"){$_ -replace "<tr>", "<tr bgcolor=Aqua>"}
elseif($_ -like "*<td>5</td>*"){$_ -replace "<tr>", "<tr bgcolor=Aqua>"}
elseif($_ -like "*<td>4</td>*"){$_ -replace "<tr>", "<tr bgcolor=Aqua>"}
elseif($_ -like "*<td>3</td>*"){$_ -replace "<tr>", "<tr bgcolor=Yellow>"}
elseif($_ -like "*<td>2</td>*"){$_ -replace "<tr>", "<tr bgcolor=Yellow>"}
elseif($_ -like "*<td>1</td>*"){$_ -replace "<tr>", "<tr bgcolor=Yellow>"}
elseif($_ -like "*<td>0</td>*"){$_ -replace "<tr>", "<tr bgcolor=Red>"}
else{$_}
} > C:\inetpub\wwwroot\default.htm
72 changes: 72 additions & 0 deletions Tools/Get-VMHealthCheck/Get-VMHealthCheck.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<#
.Synopsis
Script from TechDays Sweden 2016
.DESCRIPTION
Script from TechDays Sweden 2016
.NOTES
Author - Mikael Nystrom
Twitter: @mikael_nystrom
Blog : http://deploymentbunny.com
Disclaimer:
This script is provided "AS IS" with no warranties, confers no rights and
is not supported by the authors or Deployment Artist.
.LINK
http://www.deploymentbunny.com
#>
$HyperVHosts = "demohost03.network.local"

Foreach($HyperVHost in $HyperVHosts){
Write-Host "Checking netaccess to $HyperVHost" -ForegroundColor Green
Test-Connection -ComputerName $HyperVHost

Invoke-Command -ComputerName $HyperVHost -ScriptBlock {
Write-Host "Base info:" -ForegroundColor Green
$Win32_computersystem = Get-WmiObject -Class Win32_computersystem
Write-Host "$($Win32_computersystem.Name), $($Win32_computersystem.Model), $("{0:N0}" -f ($Win32_computersystem.TotalPhysicalMemory/1GB)) GB"
Get-Volume | FT
Get-WmiObject -Class Win32_Processor | Select-Object Name | FT
}

Invoke-Command -ComputerName $HyperVHost -ScriptBlock {
$VM = Get-VM

Write-Host "The total number of VM's on this host is: ": -ForegroundColor Green
$VM.Count

Write-Host "The following VM's are running": -ForegroundColor Green
$VM | Where-Object -Property State -EQ -Value Running | FT -AutoSize

Write-Host "The following VM's have DiffDisks": -ForegroundColor Green
$VMHardDiskDrives = $VM | Get-VMHardDiskDrive
$VMsWithDiff = foreach($VMHardDiskDrive in $VMHardDiskDrives){
if($VMHardDiskDrive.Path | Get-VHD | Where-Object -Property VhdType -EQ -Value Differencing){
$VMHardDiskDrive.VMName
}
}
$VMsWithDiff | FT -AutoSize

Write-Host "The following DiffDisks are in use": -ForegroundColor Green
$VMHardDiskDrives = $VM | Get-VMHardDiskDrive
$DiffDisks = foreach($VMHardDiskDrive in $VMHardDiskDrives){
if($VMHardDiskDrive.Path | Get-VHD | Where-Object -Property VhdType -EQ -Value Differencing){
$VMHardDiskDrive.Path
}
}
$DiffDisks | FT -AutoSize

Write-Host "The following VM's have SnapShots": -ForegroundColor Green
$VM | Get-VMSnapshot | FT -AutoSize

Write-Host "Checking for NetAdapter issues": -ForegroundColor Green
$VMNetworkAdapters = $VM | Get-VMNetworkAdapter
$VMNetworkAdapters | Select-Object VMName,MacAddress,DynamicMacAddressEnabled,IsLegacy,SwitchName,Status,IPAddresses | FT -AutoSize

Write-Host "Checking for CPU issues:" -ForegroundColor Green
$VMProcessor = $VM | Get-VMProcessor
$VMProcessor | Select-Object VMName,Count,CompatibilityForMigrationEnabled,CompatibilityForOlderOperatingSystemsEnabled,ExposeVirtualizationExtensions,OperationalStatus | FT -AutoSize

Write-Host "Checking for Memory issues:" -ForegroundColor Green
$VMMemory = $VM | Get-VMMemory
$VMMemory | Select-Object VMName,DynamicMemoryEnabled,Startup, Minimum,Maximum | FT -AutoSize
}
}
23 changes: 23 additions & 0 deletions Tools/Get-WSUSHealthCheck/Get-WSUSHealthCheck.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$WSUSServers = "SRVWSUS02.network.local"
Foreach($WSUSServer in $WSUSServers){
Write-Host "Checking netaccess to $WSUSServer" -ForegroundColor Green
Test-Connection -ComputerName $WSUSServer

Invoke-Command -ComputerName $WSUSServer -ScriptBlock {
Write-Host "Base info:" -ForegroundColor Gray
Get-WsusServer | Select-Object *
}

Invoke-Command -ComputerName $WSUSServer -ScriptBlock {
$enus = 'en-US' -as [Globalization.CultureInfo]
$TimeToCheck = (get-date).AddDays(-10).ToString("M/d/yyyy hh:mm tt", $enus)
$ComputersWNoReport = Get-WsusComputer -All | Where-Object -Property LastReportedStatusTime -LT -Value $TimeToCheck | Select-Object FullDomainName,Make,Model,LastSyncTime | FT
Write-Host "The following computers have not reported to WSUS in 10 days..." -ForegroundColor Green
$ComputersWNoReport
}

Invoke-Command -ComputerName $WSUSServer -ScriptBlock {
Write-Host "The following updates are unapproved but needed" -ForegroundColor Green
Get-WsusUpdate -Approval Unapproved -Status Needed
}
}
Loading

0 comments on commit 53c912d

Please sign in to comment.