defrag script for sysinternal contig

Page 3 of 5 FirstFirst 12345 LastLast

  1. Posts : 7,607
    Windows 10 Home 20H2
       #21

    LesFerch said:
    This should get you started:
    I ran it and got the following:

    defrag script for sysinternal contig-edefrag.jpg


    $LogFile was not created.
      My Computer


  2. Posts : 745
    Windows 10/11
       #22

    Matthew Wai said:
    I ran it and got the following:

    defrag script for sysinternal contig-edefrag.jpg

    $LogFile was not created.
    Contig.exe is a pre-req. Download it from https://docs.microsoft.com/en-us/sys...wnloads/contig

    I'll add a check for that.
      My Computer


  3. Posts : 7,607
    Windows 10 Home 20H2
       #23

    I downloaded Contig, ran your script, and got the following:

    defrag script for sysinternal contig-edefrag.jpg

    LesFerch said:
    I'll add a check for that.
    Why not add the following line to download it?

    Code:
    IWR -URI 'https://download.sysinternals.com/files/Contig.zip' -OutFile "E:\Testing\Contig.zip"

    Then use Expand-Archive to extract the files.

    Do you intend to use Optimize-Volume? If not, what will you use?
      My Computer


  4. Posts : 745
    Windows 10/11
       #24

    @Matthew Wai I added a check for Contig.exe on the path and the current folder. Yes, code could be added to download Contig.exe, but then you could argue that the code should also check if the machine is 64bit and run that version if it is. The enhancements may never end. Anyhow, it's not my script. I was just helping @einstein1969 get started. It's up to him now to add further enhancements.
      My Computer


  5. Posts : 745
    Windows 10/11
       #25

    @einstein1969 I'm not sure there is any value in finding the "Allocated Size" values from the command "FSUtil File Layout". Here is the output from Contig and FSUtil for a large file that has 20 fragments:

    Code:
    Contig "C:\Movies\Fragmented File Test.mkv"
    
    Contig v1.8 - Contig
    Copyright (C) 2001-2016 Mark Russinovich
    Sysinternals
    
    
    Summary:
         Number of files processed:      1
         Number of files defragmented:   1
         Number unsuccessfully procesed: 0
         Average fragmentation before: 20 frags/file
         Average fragmentation after : 20 frags/file
    Code:
    fsutil file layout "C:\Movies\Fragmented File Test.mkv"
    
    ********* File 0x00c4000000013d76 *********
    File reference number   : 0x00c4000000013d76
    File attributes         : 0x00000020: Archive
    File entry flags        : 0x00000000
    Link (ParentID: Name)   : 0x018c0000000018ed: DOS Name     : FRAGME~1.MKV
    Link (ParentID: Name)   : 0x018c0000000018ed: NTFS Name    : \Movies\Fragmented File Test.mkv
    Creation Time           : 3/7/2021 14:14:23
    Last Access Time        : 7/14/2021 14:22:07
    Last Write Time         : 5/18/2021 0:51:16
    Change Time             : 7/14/2021 14:22:07
    LastUsn                 : 61,538,451,304
    OwnerId                 : 0
    SecurityId              : 28921
    StorageReserveId        : 0
    Stream                  : 0x010  ::$STANDARD_INFORMATION
        Attributes          : 0x00000000: *NONE*
        Flags               : 0x0000000c: Resident | No clusters allocated
        Size                : 72
        Allocated Size      : 72
    Stream                  : 0x030  ::$FILE_NAME
        Attributes          : 0x00000000: *NONE*
        Flags               : 0x0000000c: Resident | No clusters allocated
        Size                : 90
        Allocated Size      : 96
    Stream                  : 0x030  ::$FILE_NAME
        Attributes          : 0x00000000: *NONE*
        Flags               : 0x0000000c: Resident | No clusters allocated
        Size                : 114
        Allocated Size      : 120
    Stream                  : 0x080  ::$DATA
        Attributes          : 0x00000000: *NONE*
        Flags               : 0x00000010: Has Parsed Information
        Size                : 5,868,919,362 (5.5 GB)
        Allocated Size      : 5,868,920,832 (5.5 GB)
        Vdl                 : 5,868,919,362 (5.5 GB)
        Extents             : 20 Extents
    Maybe you should be looking at the output of "FSUtil File QueryExtents"? This is what I got for the same test file:

    Code:
    fsutil file queryextents "C:\Movies\Fragmented File Test.mkv"
    VCN: 0x0        Clusters: 0x3f31     LCN: 0x6d559f
    VCN: 0x3f31     Clusters: 0x4f3d     LCN: 0x15b8123
    VCN: 0x8e6e     Clusters: 0xbafc     LCN: 0x146fd9c
    VCN: 0x1496a    Clusters: 0xbd60     LCN: 0x18c2f78
    VCN: 0x206ca    Clusters: 0xc224     LCN: 0x12fcdd8
    VCN: 0x2c8ee    Clusters: 0xc27c     LCN: 0x44b8e78
    VCN: 0x38b6a    Clusters: 0x157ac    LCN: 0x28873c4
    VCN: 0x4e316    Clusters: 0xc9c0     LCN: 0x30641e8
    VCN: 0x5acd6    Clusters: 0xe004     LCN: 0x131ae54
    VCN: 0x68cda    Clusters: 0x16730    LCN: 0x16975b8
    VCN: 0x7f40a    Clusters: 0xe004     LCN: 0x17a6108
    VCN: 0x8d40e    Clusters: 0x16c1c    LCN: 0x1af1b20
    VCN: 0xa402a    Clusters: 0x17088    LCN: 0x6c8ad54
    VCN: 0xbb0b2    Clusters: 0x17788    LCN: 0x4b0fa20
    VCN: 0xd283a    Clusters: 0x177f0    LCN: 0x21a3be0
    VCN: 0xea02a    Clusters: 0x17bd8    LCN: 0x2a3d488
    VCN: 0x101c02   Clusters: 0x19a74    LCN: 0x102a2a8
    VCN: 0x11b676   Clusters: 0x19cfc    LCN: 0x309a140
    VCN: 0x135372   Clusters: 0x1ad9a    LCN: 0x1cb8860
    VCN: 0x15010c   Clusters: 0xdbfe     LCN: 0x30c2f58
      My Computer


  6. Posts : 250
    Windows 10 22H2
    Thread Starter
       #26

    Matthew Wai said:
    In addition to Paul's suggestion, you may use VBScript to run it as an administrator.

    Code:
    Set l=CreateObject("Shell.Application"):If WScript.Arguments.length=0 Then
    l.ShellExecute"wscript.exe",""""&WScript.ScriptFullName&""""&" +","","RunAs",1
    Else
    Set X=CreateObject("WScript.Shell"):File="E:\Testing.ps1"
    X.run("powershell -executionpolicy bypass -File "&""""&File&"""")
    End if

    Replace "E:\Testing.ps1" with the actual file path. It works as a shortcut.
    I have used the same code in the following:
    Using CMD script and VBScript to control Windows Update

    Hi Matthew, thank you.
    She'll meet again after a while. I got busy, but still worked a little bit for that logging problem. When I can continue.

    - - - Updated - - -

    LesFerch said:
    I see that says "Cannot find the specified file". Two possible reasons come to mind:

    1. The file was deleted (e.g. temp file) or renamed between the time Contig scanned it and FSUtil was run.

    2. There are unusual permissions set on the file that cause it to be seen by Contig, but not by FSUtil.

    I added a file existence check in the FSUtill function. That should fix it. If not, let's look closer at the files causing that error.
    I updated the ps1 script but I can't find the size of any file on disk C.

    Code:
    C:\users\All Users\Microsoft\EdgeUpdate\Log\MicrosoftEdgeUpdate.log | 22 | 
    C:\users\All Users\Microsoft\Windows\DeviceMetadataCache\dmrc.idx | 4 | 
    C:\users\All Users\Microsoft\Windows Security Health\Logs\SHS-07122021-170346-7-7f-19041.1.amd64fre.vb_release.191206-1406.etl | 5 | 
    C:\users\All Users\Microsoft\Windows Security Health\Logs\SHS-07132021-184421-7-7f-19041.1.amd64fre.vb_release.191206-1406.etl | 4 | 
    C:\users\All Users\USOShared\Logs\System\MoUsoCoreWorker.0349849c-dbcc-40bf-ad8a-651c04d70161.1.etl | 4 |
    On the external drive it seems to work instead

    Code:
    N: \ bck \ backup_macrium \ Version 1809 base \ FABC4503751A17D2-00-00.mrimg | 4 | 48 128 80 11,651,563,520 (10.9 GB) 57,344
    For language-dependent strings we can do without it:
    You actually need the size allocated only for the stream ::$DATA
    it is the fourth value in the section ::$DATA

    For some files it does not work in the log I find:

    Code:
    M: \ Labyrinth - Where Everything Is Possible - Ita_Eng.mkv | 15 | File cannot be found


    and it looks like the code page problem I told you.

    For reproduce problem try:

    - download Victoria 5.36 (Victoria536.zip)
    - extract
    - found Русский.lng file
    - try to fragment:
    - for / L% L in (1,1,8) do type Русский.lng >> Русский.lng

    - - - Updated - - -

    Sorry the error message is:
    Code:
    M:\Labyrinth - Dove Tutto ╚ Possibile - Ita_Eng.mkv | 15 | File cannot be found
    - - - Updated - - -

    @all

    the 64bit has bug and don't work well, use 32bit version of contig. work well for 32 and 64 bit.

    add note that contig64 is broken . Issue #57 . MicrosoftDocs/sysinternals . GitHub

    - - - Updated - - -

    perhaps version 1.7 ...

    https://social.technet.microsoft.com...orum=miscutils
      My Computers


  7. Posts : 7,607
    Windows 10 Home 20H2
       #27

    einstein1969 said:
    I updated the ps1 script but I can't find the size of any file on disk C.
    The script retrieved the sizes of the files on my drive C.

    Code:
    C:\ProgramData\Malwarebytes\MB3Service\dbupdate.log | 7 |  72  96  1,638,400 (1.6 MB) 
    C:\ProgramData\Malwarebytes\MB3Service\Global.sr | 13 |  72  88  20,140,032 (19.2 MB) 
    C:\ProgramData\Malwarebytes\MB3Service\rules.mbdb | 94 |  72  88  88  21,979,136 (21.0 MB) 
    C:\ProgramData\Malwarebytes\MB3Service\scan.mbdb | 11 |  72  88  88  1,748,992 (1.7 MB) 
    C:\ProgramData\Malwarebytes\MB3Service\tids.mbdb | 5 |  72  88  88  253,952 (248.0 KB) 
    C:\ProgramData\Malwarebytes\MB3Service\ARW\mbarwind.arw | 13 |  72  96  13,107,200 (12.5 MB) 
    C:\ProgramData\Malwarebytes\MB3Service\lkg_db\Global.sr | 17 |  72  88  20,140,032 (19.2 MB)  56 
    C:\ProgramData\Malwarebytes\MB3Service\lkg_db\rules.mbdb | 8 |  72  88  88  21,979,136 (21.0 MB) 
    C:\ProgramData\Malwarebytes\MB3Service\lkg_db\wprot2.mbdb | 11 |  72  88  96  19,456,000 (18.6 MB) 
    C:\ProgramData\Malwarebytes\MB3Service\LOGS\MBAMSERVICE.LOG | 13 |  72  96  96  7,602,176 (7.3 MB)

    I am running an English version of Windows 10 with no Chinese language pack.
      My Computer


  8. Posts : 7,607
    Windows 10 Home 20H2
       #28

    einstein1969 said:
    I updated the ps1 script but I can't find the size of any file on disk C.
    Right-click on the Start button --> Windows PowerShell
    Run the following command and see whether the size will be displayed.
    Code:
    Write-Host([math]::round((Get-Item "C:\users\All Users\Microsoft\EdgeUpdate\Log\MicrosoftEdgeUpdate.log").Length/1MB,2))MB
    The following is my example output:
    Code:
    PS C:\Users\Matthew_Wai> Write-Host([math]::round((Get-Item "C:\users\All Users\Microsoft\EdgeUpdate\Log\MicrosoftEdgeUpdate.log").Length/1MB,2))MB
    5.29 MB


    I acknowledge receipt of your PM.
    Stack Overflow is a weird site. Previously, it banned me from asking questions there. Recently, it has sent me an email, saying that "Because of recent increases to your Super User reputation, you now have the ability to participate in review queues". It is ironic.
      My Computer


  9. Posts : 250
    Windows 10 22H2
    Thread Starter
       #29

    @LesFerch
    I have tried utf-8+bom and utf-16LE but the problem remain

    @Matthew Wai
    Code:
    PS C:\Users\fposc> Write-Host([math]::round((Get-Item "C:\users\All Users\Microsoft\EdgeUpdate\Log\MicrosoftEdgeUpdate.log").Length/1MB,2))MB
    4,05 MB
    PS C:\Users\fposc>

    Ok, I have solved the problem with disk C: I misunderstood and thought it was running as admin. I had to do the VBS because Paul Black's first method I couldn't get it to work.
    I also solved part of the coding problem the same way I did in batch. How do I change the code page in powershell?

    Code:
    PS C:\Users\fposc\Downloads\powerdefragmentergui> powershell -f .\Edefrag.ps1
    Ricerca di file frammentati...
    Analizza i file con minimo 4 frammenti...
    M:\Labyrinth - Dove Tutto ╚ Possibile - Ita_Eng.mkv | 15 | File cannot be found
    PS C:\Users\fposc\Downloads\powerdefragmentergui> chcp 1252
    Tabella codici attiva: 1252
    PS C:\Users\fposc\Downloads\powerdefragmentergui> powershell -f .\Edefrag.ps1
    Ricerca di file frammentati...
    Analizza i file con minimo 4 frammenti...
    M:\Labyrinth - Dove Tutto È Possibile - Ita_Eng.mkv | 15 |  72  168  16  4.699.717.632 (4,4 GB)  32 (0,0 KB)
    PS C:\Users\fposc\Downloads\powerdefragmentergui>
    Last edited by einstein1969; 15 Jul 2021 at 17:54.
      My Computers


  10. Posts : 745
    Windows 10/11
       #30

    @einstein1969 I finally got the code page problem fixed. I updated the code in my original message.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 15:02.
Find Us




Windows 10 Forums