GetDiskFreeSpaceEx.ps1 : script qui donne les infos d'espace disque sur C:\ - FONCTIONNE **************************************** <# BOOL WINAPI GetDiskFreeSpaceEx( __in_opt LPCTSTR lpDirectoryName, __out_opt PULARGE_INTEGER lpFreeBytesAvailable, __out_opt PULARGE_INTEGER lpTotalNumberOfBytes, __out_opt PULARGE_INTEGER lpTotalNumberOfFreeBytes ); #> # Just declare Win32 API... $a = Add-Type -memberDefinition @" [DllImport("Kernel32.dll")] public static extern bool GetDiskFreeSpaceEx( string lpDirectoryName, IntPtr lpFreeBytesAvailable, IntPtr lpTotalNumberOfBytes, IntPtr lpTotalNumberOfFreeBytes ); "@ -passthru -name MyGetDiskFreeSpaceEx # Alloc some memory ... $fba = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); $tnb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); $nfb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); # Call 'GetDiskFreeSpaceEx' ... $a::GetDiskFreeSpaceEx("C:\", $fba, $tnb, $nfb) # Get the Value storing in the memory pointed by $fba... $x = [System.Runtime.InteropServices.Marshal]::ReadInt64($fba) $y = [System.Runtime.InteropServices.Marshal]::ReadInt64($tnb) $z = [System.Runtime.InteropServices.Marshal]::ReadInt64($nfb) # Display the result ... "FreeBytesAvailable: $($x)" "TotalNumberOfBytes: $($y)" "TotalNumberOfFreeBytes: $($z)" # !! Free the memory ASAP.... [System.Runtime.InteropServices.Marshal]::FreeHGlobal($fba); [System.Runtime.InteropServices.Marshal]::FreeHGlobal($tnb); [System.Runtime.InteropServices.Marshal]::FreeHGlobal($nfb); **************************************** GetDiskClusterInfo.ps1 : script qui donne les infos de cluster sur C:\ - NE FONCTIONNE PAS **************************************** <# BOOL WINAPI GetDiskFreeSpace( __in LPCTSTR lpRootPathName, __out LPDWORD lpSectorsPerCluster, __out LPDWORD lpBytesPerSector, __out LPDWORD lpNumberOfFreeClusters, __out LPDWORD lpTotalNumberOfClusters ); #> # Just declare Win32 API... $b = Add-Type -memberDefinition @" [DllImport("Kernel32.dll")] public static extern bool GetDiskFreeSpace( string lpRootName, IntPtr lpSectorsPerCluster, IntPtr lpBytesPerSector, IntPtr lpNumberOfFreeClusters IntPtr lpTotalNumberOfClusters ); "@ -passthru -name MyGetDiskFreeSpace # Alloc some memory ... $spc = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); $bps = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); $nfc = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); $tnc = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20); # Call 'GetDiskFreeSpace' ... $b::GetDiskFreeSpace("C:\", $spc, $bps, $nfc, $tnc) # Get the Value stored in the memory pointed by $spc... $x = [System.Runtime.InteropServices.Marshal]::ReadInt32($spc) $y = [System.Runtime.InteropServices.Marshal]::ReadInt32($bps) $z = [System.Runtime.InteropServices.Marshal]::ReadInt32($nfc) $t = [System.Runtime.InteropServices.Marshal]::ReadInt32($tnc) # Display the result ... "SectorsPerCluster: $($x)" "BytesPerSector: $($y)" "NumberOfFreeClusters: $($z)" "TotalNumberOfClusters: $($t)" # !! Free the memory ASAP.... [System.Runtime.InteropServices.Marshal]::FreeHGlobal($spc); [System.Runtime.InteropServices.Marshal]::FreeHGlobal($bps); [System.Runtime.InteropServices.Marshal]::FreeHGlobal($nfc); [System.Runtime.InteropServices.Marshal]::FreeHGlobal($tnc); ****************************************