Blog Arksoft
  • Arksoft Bilisim
  • Scripts
    • SCCM (ConfigMgr)
    • Hyper-V
    • WSUS
    • Exchange Scripts
      • Exchange Virtual Directory Config
      • Virtual Directory Script
      • LogPath Config
  • NİSAN 2025
    • Microsoft’un Mayıs 2025 Güncellemeleri: Sistem Yöneticileri İçin Kapsamlı Özet
    • Exchange Server 2019 CU15 Apr25HU
    • Nisan 2025:Microsoft Güvenlik Güncellemeleri
    • Power BI Gateway ile On-Prem Verilerin Gücünü Keşfedin!
    • IT Personelleri Neden Adli Bilişim Farkındalık Eğitimi Almalıdır?
    • ''SCCM 2503'' Sürüm Yükseltme Rehberi
  • Mart 2025
    • SCCM Üzerinden Kritere Göre Uygulama ve Deployment’ları Otomatik Silmek
    • Mart 2025: Microsoft Güvenlik Güncellemeleri
  • ŞUBAT 2025
    • SPN Nedir, Kerberos Nasıl Çalışır ve Duplicate SPN Neden Sorun Yaratır?
    • Şubat 2025: Microsoft'un Güvenlik Güncellemeleriyle Sistemlerinizi Güçlendirin!
    • Exchange Server CU15 Güncellemesi
    • log_reuse_wait_desc Nedir ve Ne Anlatır?
  • OCAK 2025
    • Azure SQL Nedir? Temel Bilgiler ve Avantajlar
    • Live Migration için Ağ Kartı Seçerken Dikkat Edilmesi Gerekenler
    • Protected Attribute Nedir? Nasıl Oluşturulur?
    • Ocak 2025 Microsoft Güvenlik Güncellemeleri: Sistemlerinizi Güvende Tutun!
    • CLIUSR Hesabı Neden Önemlidir? CLIUSR sertifikası nedir, neden süresi doldu uyarısı alıyorum?
  • ARALIK 2024
    • TLS 1.2 Öncesi Protokollerin Güvenlik Açıkları ve TLS 1.2/1.3 Önemi
  • Kasım 2023
    • Microsoft Exchange Server Kasım Ayı Güvenlik Güncellemesi
  • Temmuz 2023
    • Microsoft Office Zero-Day Zafiyeti CVE-2023-36884
  • Mayis 2023
    • Hashing ve Salting Kavramları Nedir? Azure AD Parola Güvenliği Nasıl Sağlanır?
  • Nisan 2023
    • DDOS Saldırıları Nedir ve Korunma Yolları Nelerdir?
    • Fidye Yazılımları Nedir ve Korunma Yöntemleri Nelerdir?
    • Ransomwares And Defence Strategies
    • PowerShell Modülleri: Temel Kavramlar ve Kullanım Örnekleri
    • PowerShell Fonksiyonları: Temel Kavramlar ve Kullanım Örnekleri
    • PowerShell Cmdlet'ler: Temel Kavramlar ve Kullanım Örnekleri
    • PowerShell Değişkenleri: Temel Kavramlar ve Kullanım Örnekleri
    • PowerShell Nedir?
    • Oltalama E-Postalarından Korunma
    • CVE-2023-2033
    • Cloud Computing and Its Advantages
    • Bulut Bilişim Nedir ve Bulut Bilişimin Avantajları Nelerdir?
    • Bilgi ve İletişim Güvenliği Rehberi Nedir ve Rehbere Uyumlu Olmak Neden Önemlidir?
  • Mart 2023
    • Sık Kullanılan Portlar ve Üzerinde Çalışan Protokoller
    • Siber Güvenlik ve İnternet Dünyasında Güvende Kalmanın Yolları
    • Outlook Kullanıcılarına Uyarı: CVE-2023-23397 Güvenlik Açığına Karşı Önlem Alın
  • Şubat 2023
    • Üçüncü Parti Uygulamaların Güncellenmesinin Önemi
  • Aralık 2022
    • Siber Tehdit
    • FRS to DFSR Migration
  • Kasım 2022
    • Domain Controller 2022 Kasım Ayı Bug'ı
  • Mart 2022
    • OWA ve ECP erişim sorunu: Microsoft Exchange Server Auth Certificate is expired
    • MIM 2016 SSPR Türkçe Karakter Problemi
  • Haziran 2021
    • KMS (Key Management Service)
  • Ağustos 2020
    • Microsoft Teams Konuk (Guest) Erişimi ve Dış (External) Erişim- Sizin için hangisi uygun?1
    • SCCM 2006 Güncellemesi
    • Skype For Business 2019 Kurulumu- Hata Kodu 1603 (Server.msi(Feature_Server, Feature_HealthyAgent))
    • Skype for Business 2019 “Centralized Logging” Servisinin Başlatılamaması Problemi ve Çözümü
  • Temmuz 2020
    • Clean Inactive Agents from Operations Manager
  • Haziran 2020
    • Microsoft Teams Katılımcı Raporu İndirme
    • Microsoft Teams Toplantı ve Grup Sohbet Sınırı 300'e çıkarıldı
  • Mayıs 2020
    • MIM 2016 Service and Portal Kurulumundaki Bug
    • Telegram ve Powershell ile Sistem İzleme-Part 1
  • Ekim 2019
    • Windows Server 2019 Active Directory Domain Services Kurulumu
  • Nisan 2019
    • Huawei FusionCompute Kurulumu
  • Mart 2019
    • Password Reveal Düğmesi
  • Ocak 2019
    • ReportServer Veri Tabanı içerisinden RDL Dosyalarının Çıkartılması
  • Temmuz 2018
    • Active Directory Certificate Services - SHA1’ den SHA2’ ye Yükseltme
    • Local Administrator Password Solution
Powered by GitBook
On this page
  • Convert Dynamic VHDX to Fixed VHDX
  • Usage
  • Find&Move Orphand Virtual Hard Disk Files
  • Usage
  • Grant-VMVhdPermission
  • Usage
  1. Scripts

Hyper-V

Convert Dynamic VHDX to Fixed VHDX

function Convert-VMDisksToFixed {
    param (
        [Parameter(Mandatory)]
        [string]$VMName,

        [Parameter(Mandatory)]
        [array]$Disks  # Her disk için @{Old="..." ; New="..."}
    )

    # VM SID bul
    try {
        $vmId = (Get-VM $VMName).Id.Guid
        $vmSid = "NT VIRTUAL MACHINE\$vmId"
    } catch {
        Write-Error "❌ VM '$VMName' bulunamadı."
        return
    }

    foreach ($disk in $Disks) {
        $oldPath = $disk.Old
        $newPath = $disk.New

        if (-not (Test-Path $oldPath)) {
            Write-Warning "⚠️ Disk bulunamadı: $oldPath"
            continue
        }

        $vhdInfo = Get-VHD -Path $oldPath

        if ($vhdInfo.VhdType -ne 'Fixed') {
            Write-Host "`n🔄 Converting to fixed: $oldPath -> $newPath"
            Convert-VHD -Path $oldPath -DestinationPath $newPath -VHDType Fixed -ErrorAction Stop
            Remove-Item -Path $oldPath -Force
        } else {
            Write-Host "`n🔁 Already fixed: Renaming $oldPath -> $newPath"
            Rename-Item -Path $oldPath -NewName (Split-Path $newPath -Leaf)
        }

        # NTFS izinlerini ayarla
        try {
            $acl = Get-Acl $newPath
            $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($vmSid, "FullControl", "Allow")
            $acl.AddAccessRule($accessRule)
            Set-Acl -Path $newPath -AclObject $acl
            Write-Host "✅ NTFS izinleri eklendi: $vmSid → $newPath"
        } catch {
            Write-Warning "❌ İzin ayarlanamadı: $newPath - $_"
        }
    }

    Write-Host "`n🎯 İşlem tamamlandı."
}

Usage

$vmName = "VM01"
$disks = @(
    @{Old="E:\HYPERV\VM01\SomeDynamicDisk1.vhdx"; New="E:\HYPERV\VM01\VM01-C-DRIVE.vhdx"},
    @{Old="E:\HYPERV\VM01\SomeFixedDisk1.vhdx"; New="E:\HYPERV\VM01\VM01-D-DRIVE.vhdx"},
    @{Old="E:\HYPERV\VM01\SomeDynamicDisk2.vhdx"; New="E:\HYPERV\VM01\VM01-E-DRIVE.vhdx"}
)

Convert-VMDisksToFixed -VMName $vmName -Disks $disks

Find&Move Orphand Virtual Hard Disk Files

function Find-AndMoveUnusedVHDs {
    param(
        [string]$SearchPath = "E:\HYPERV",
        [string]$MoveFolder = "E:\HYPERV\Orphans",
        [bool]$MoveStaledVMs = $false,
        [string]$LogFolder = "C:\Logs"
    )

    if (-not (Test-Path $SearchPath)) {
        Write-Error "Search path does not exist: $SearchPath"
        return
    }

    if (-not (Test-Path $LogFolder)) {
        New-Item -Path $LogFolder -ItemType Directory | Out-Null
    }

    $LogPath = Join-Path -Path $LogFolder -ChildPath "MovedVHDs_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
    New-Item -Path $LogPath -ItemType File -Force | Out-Null

    $usedDisks = Get-VM | Get-VMHardDiskDrive | Select-Object -ExpandProperty Path
    $vhdFiles = Get-ChildItem -Path $SearchPath -Recurse -Include *.vhd, *.vhdx -ErrorAction SilentlyContinue

    foreach ($file in $vhdFiles) {
        if ($usedDisks -notcontains $file.FullName) {
            Write-Host "Unused disk found: $($file.FullName)"

            if ($MoveStaledVMs) {
                if (-not (Test-Path $MoveFolder)) {
                    New-Item -Path $MoveFolder -ItemType Directory | Out-Null
                }

                $destinationBase = Join-Path -Path $MoveFolder -ChildPath $file.Name
                $destination = $destinationBase
                $i = 1

                while (Test-Path $destination) {
                    $destination = Join-Path -Path $MoveFolder -ChildPath ("$($file.BaseName)_$i$($file.Extension)")
                    $i++
                }

                Move-Item -Path $file.FullName -Destination $destination -Force

                $logLine = "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] MOVED: '$($file.FullName)' => '$destination' | Last Modified: $($file.LastWriteTime)"
                Add-Content -Path $LogPath -Value $logLine
                Write-Host $logLine -ForegroundColor Green
            }
        }
    }

    Write-Host "İşlem tamamlandı. Log dosyası: $LogPath" -ForegroundColor Cyan
}

Usage

Find-AndMoveUnusedVHDs -SearchPath "E:\HYPERV" -MoveStaledVMs $true -MoveFolder "E:\HYPERV\Orphans" -LogFolder "C:\Logs"

Grant-VMVhdPermission

function Grant-VMVhdPermission {
    param (
        [Parameter(Mandatory)]
        [string]$VMName,

        [Parameter(Mandatory)]
        [string]$DiskPath
    )

    # Get VM SID
    try {
        $vmId = (Get-VM $VMName).Id.Guid
        $vmSid = "NT VIRTUAL MACHINE\$vmId"
    } catch {
        Write-Error "❌ Failed to find the VM '$VMName'."
        return
    }

    if (-not (Test-Path $DiskPath)) {
        Write-Error "❌ Disk path does not exist: $DiskPath"
        return
    }

    try {
        $acl = Get-Acl $DiskPath
        $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($vmSid, "FullControl", "Allow")
        $acl.AddAccessRule($accessRule)
        Set-Acl -Path $DiskPath -AclObject $acl

        Write-Host "✅ Permission successfully granted: $vmSid → $DiskPath"
    } catch {
        Write-Warning "❌ Error while setting permissions: $_"
    }
}

Usage

Grant-VMVhdPermission -VMName "VM01" -DiskPath "E:\HYPERV\VM01\VM01-C-DRIVE.vhdx"
PreviousSCCM (ConfigMgr)NextWSUS

Last updated 27 days ago