Skip to content

Instantly share code, notes, and snippets.

@awsvpc
awsvpc / DCHealthCheck.ps1
Created April 26, 2024 00:40 — forked from maxautomation/DCHealthCheck.ps1
Domain Controller Health Check
$Header = @"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
$smtphost = "smtp.domain.com"
$from = "AutomatedAgent@domain.com"
@awsvpc
awsvpc / EnableDeleteOnTermination.ps1
Created April 26, 2024 00:40 — forked from maxautomation/EnableDeleteOnTermination.ps1
Enable Delete On Termination Flag for the EBS Volume attached to EC2 Instance
$server = Read-Host "Please provide the server name"
$InstanceId = (Get-EC2Instance | ?{$_.Instances.tag.value -like $server}).Instances.InstanceId
$deviceids = (Get-EC2InstanceAttribute -InstanceId $InstanceId -Attribute blockDeviceMapping | Select -ExpandProperty BlockDeviceMappings).DeviceName
foreach($deviceid in $deviceids)
{
Edit-EC2InstanceAttribute -InstanceId $InstanceId -BlockDeviceMapping @{DeviceName=$deviceid;Ebs=@{DeleteOnTermination=$true}};
}
Function Get-Device() {
param(
[parameter (mandatory=$true)][string] $InstanceId
)
$CurrentDevice = Get-EC2InstanceAttribute $InstanceId -Attribute blockDeviceMapping | Select-Object -ExpandProperty BlockDeviceMappings | Select-Object -last 1
If ($CurrentDevice.DeviceName -eq '/dev/sda1') {
$NewDevice = 'xvdf'
return $NewDevice
}
Else {
@awsvpc
awsvpc / CreatenAttachEBS,ps1
Created April 26, 2024 00:38 — forked from maxautomation/CreatenAttachEBS,ps1
Create and Attach EBS volume to running EC2 Instance
param(
[parameter(mandatory=$true,HelpMessage="Please enter EC2 Instance Name")][string] $InstanceName,
[parameter(mandatory=$true)][int] $VolumeSize,
[parameter(mandatory=$false)][string] $Device,
[parameter(mandatory=$true)][string] $VolumeType
)
$Filter = New-Object Amazon.EC2.Model.Filter
$Filter.Name = 'tag:Name'
$Filter.Value = "$InstanceName"
$Reservation = Get-EC2Instance -Filter $Filter | Select-Object -ExpandProperty instances
Function Initialize-EC2Disk {
param(
[parameter (mandatory=$true)][string] $InstanceId
)
$Commands = @(
'Get-Disk | `
Where partitionstyle -eq "raw" | `
Initialize-Disk -PartitionStyle MBR -PassThru | `
New-Partition -AssignDriveLetter -UseMaximumSize | `
Format-Volume -FileSystem NTFS -Confirm:$false -force'
@awsvpc
awsvpc / ExtendVMDisk.ps1
Created April 26, 2024 00:37 — forked from maxautomation/ExtendVMDisk.ps1
Script to Extend the VM disk from Vcenter as well as from OS end
Connect-VIServer vcentername
$compName = Read-Host "Please provide the Server Name"
$inputdrive = Read-Host "Please provide the drive letter that needs to be extended"
$inputdrive1 = $inputdrive + ":"
[int]$sizetoincrease = Read-Host "Please provide the size you want to increase in GB"
$snapshot = Get-Snapshot -VM $compName
if(!$snapshot)
{
@awsvpc
awsvpc / GetManufacturer.ps1
Created April 26, 2024 00:37 — forked from maxautomation/GetManufacturer.ps1
Ger Manufacturer details for a list of servers
$Results = @()
$servers = Get-Content C:\Script\list.txt
foreach($server in $servers)
{
Try
{
$Manufacturer = Get-WmiObject WIn32_computerSystem -ComputerName $server -ErrorAction Stop | Select -ExpandProperty Manufacturer
}
Catch
$servers = Get-ADComputer -Filter { OperatingSystem -like "*Windows Server*"} | Select -ExpandProperty Name
Write-Host " Total No of Server Objects found in AD - $($servers.Count) " -ForegroundColor Cyan
$Results = @()
foreach($server in $servers)
{
If (Test-Connection $server -Count 1 -ErrorAction SilentlyContinue)
{
$Results = @()
Import-AzContext -Path C:\Users\Script\test.json
$subscriptions = Get-AzSubscription | Select -ExpandProperty Id
foreach($subscription in $subscriptions)
{
Set-AzContext -Subscription $subscription | Out-Null
$Details = Get-AzDisk | ?{$_.DiskState -eq "Unattached"}
$Details.Name
@awsvpc
awsvpc / VMDetails.ps1
Created April 26, 2024 00:37 — forked from maxautomation/VMDetails.ps1
VMDetails
$Results = @()
$Details = Get-VM | Select Name, PowerState, GuestId, @{N="VM Config File";E={$_.extensiondata.config.files.vmpathname}}
$Network = get-vm | Get-NetworkAdapter |Select -ExpandProperty NetworkName
$Properties = @{
VMName = $Details.Name
PowerState = $Details.PowerState
GuestId = $Details.GuestId
'VM Config File' = $Details.'VM Config File'
Network = $Network
}