1. Yanta

    Yanta MDL Senior Member

    May 21, 2017
    477
    274
    10
    Did you quote the wrong message?

    This is not related to my question.

     
  2. Yanta

    Yanta MDL Senior Member

    May 21, 2017
    477
    274
    10
    #26582 Yanta, Nov 17, 2023
    Last edited: Nov 17, 2023
    Well, yes, sort of. What I'm actually trying to figure out is why my powershell storage commands don't work.

    Here''s the script I have now...

    Code:
    <# : batch script
    @echo off
    powershell -nop Invoke-Expression ('$OldDrive = """"%1""""; $NewDrive = """"%2""""' + [System.IO.File]::ReadAllText('%~f0'))
    goto :eof
    #>
    
    if ((Get-Partition -DriveLetter $OldDrive -ErrorAction Ignore) -eq $null) {
        "{0}: is not assigned." -f $OldDrive
        exit 0
    }
    
    if ((Get-Partition -DriveLetter $NewDrive -ErrorAction Ignore) -ne $null) {
        "{0}: is unavailable." -f $NewDrive
        exit 0
    }
    
    try {
        Set-Partition -DriveLetter $OldDrive -NewDriveLetter $NewDrive
        "Changed {0}: to {1}:" -f $OldDrive, $NewDrive
    }
    catch {
        $_.Exception.Message
        exit 1
    }
    
    But something is broken with powershell. When using get-partition it returns nothing so I figured I probably removed a component necessary for making powershell storage commands work and my question is "What component do I need to retain".
     
  3. xlincn

    xlincn MDL Junior Member

    Nov 9, 2013
    50
    15
    0
    the new system is no longer available and is looking forward to the update
     
  4. MrNico98

    MrNico98 MDL Junior Member

    May 9, 2023
    56
    7
    0
    toolkit is dead? no update...
     
  5. Feartamixg

    Feartamixg MDL Addicted

    May 15, 2016
    783
    629
    30
    While I admit that the delay since the last update is troubling me a little, I do think we owe it to @MSMG to show our patience. They may have troubles in life or with their health right now and we should remember that @MSMG is human, just like the rest of us.
     
  6. Ace2

    Ace2 MDL Expert

    Oct 10, 2014
    1,869
    1,535
    60
    No, toolkit is not dead, the problem is, there are to many CU updates at any given time, keeping toolkit up to date, would be to much work for anyone, when they have there own life to live.
     
  7. kandido

    kandido MDL Junior Member

    Jun 14, 2015
    60
    37
    0
    you're exactly right, sir :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. inTerActionVRI

    inTerActionVRI MDL Expert

    Sep 23, 2009
    1,748
    3,575
    60
    #26588 inTerActionVRI, Nov 20, 2023
    Last edited: Nov 20, 2023
    Was this batch supposed to be run within PowerShell?
    Or was it really just a commented block to serve as a reminder?

    What are OldDrive and NewDrive Var and how did you get them?

    Whats is the expected result with "[System.IO.File]::ReadAllText('%~f0')"?
    if you need only drive, you should use %~d0.


    To run cmd code inside powershell, even if it calls powershell back, you would need to use the command cmd.exe /C.
    I made some changes to the quotation marks and that positive sign, I don't know if you wanted to concatenate the result or if you wanted to do it the way I put it, in which the 3 codes are being executed in sequence.
    Just like this:
    Code:
    cmd.exe /C "PowerShell.exe -nop Invoke-Expression ('$OldDrive = """"%1""""; $NewDrive = """"%2""""; [System.IO.File]::ReadAllText("%~f0")')"

    From what I interpreted, you are not detecting the disks, but rather, you are passing them, in the form of arguments to powershell?
    you can use $Args[0] as the first argument and $Args[1] as the second argument and so on.
    if they are not empty:
    Code:
    if ( $Args[0] ) { $OldDrive = [System.IO.Path]::GetFullPath( ( $Args[0] -Replace "\*", "%2A" ).ToString() ) }
    if ( $Args[1] ) { $NewDrive = [System.IO.Path]::GetFullPath( ( $Args[1] -Replace "\*", "%2A" ).ToString() ) }
    if ( $OldDrive ) { $OldDrive = $OldDrive.TrimEnd("\") }
    if ( $NewDrive ) { $NewDrive = $NewDrive.TrimEnd("\") }
    

    I dont know if these commands could be useful for you, but follow commands to get only Partitions with letter or only letters.
    Code:
    Get-Partition | Where-Object { $_.DriveLetter }
    
    Will get partition with and without letter
    Code:
    Get-Partition.DriveLetter
    
    Will get only letter
    Code:
    ( Get-Partition | Where-Object { $_.DriveLetter } ).DriveLetter
    
     
  9. Yanta

    Yanta MDL Senior Member

    May 21, 2017
    477
    274
    10
    #26589 Yanta, Nov 21, 2023
    Last edited: Nov 21, 2023
    Yes, the syntax is chgdrive X Y and it works fine on systems with working powershell.

    The code is correct, the problem is on any system I've built using MSMG toolkit the powershell storage commands do not work.

    If I install a vanilla, untouched 19044 21H2 they work fine.

    Not a single one of the storage commands work.
    I've checked, the storage module is installed.

    The commands would be useful to me if my powershell would run storage cmdlets, but it doesn't.
    This is a valid method of invoking poweshell within a batch script.
    Code:
    <# : batch script
    @echo off
    powershell -nop Invoke-Expression ('$OldDrive = """"%1""""; $NewDrive = """"%2""""' + [System.IO.File]::ReadAllText('%~f0'))
    goto :eof
    #>
    
    If I run chgdrive J A it will tell me drive J: is not assigned, even though it is. If I simply type get-partition at a PS prompt it returns nothing.

    Code:
    PS C:\Users\Tanya> get-disk
    PS C:\Users\Tanya> get-partition
    PS C:\Users\Tanya> get-volume
    PS C:\Users\Tanya> Get-Partition | Where-Object { $_.DriveLetter }
    PS C:\Users\Tanya> ( Get-Partition | Where-Object { $_.DriveLetter } ).DriveLetter
    PS C:\Users\Tanya> Get-Partition.DriveLetter
    Get-Partition.DriveLetter : The term 'Get-Partition.DriveLetter' is not recognized as the name of a cmdlet, function,
    script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
    correct and try again.
    At line:1 char:1
    + Get-Partition.DriveLetter
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Get-Partition.DriveLetter:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    
    I also tried installing Powershell 7.4.0 but I get the same results.

    Using
    Code:
    cmd.exe /C "PowerShell.exe -nop Invoke-Expression ('$OldDrive = """"%1""""; $NewDrive = """"%2""""; [System.IO.File]::ReadAllText("%~f0")')"
    
    results in
    Code:
    I:\PostInstall>cmd.exe /C "PowerShell.exe -nop Invoke-Expression ('$OldDrive = """"x""""; $NewDrive = """"y""""; [System.IO.File]::ReadAllText("I:\PostInstall\test.cmd")')"
    Invoke-Expression : At line:1 char:65
    + ... dDrive = "x"; $NewDrive = "y"; [System.IO.File]::ReadAllText(I:\PostI ...
    +                                                                  ~
    Missing ')' in method call.
    At line:1 char:65
    + ... ewDrive = "y"; [System.IO.File]::ReadAllText(I:\PostInstall\test.cmd)
    +                                                  ~~~~~~~~~~~~~~~~~~~~~~~
    Unexpected token 'I:\PostInstall\test.cmd' in expression or statement.
    At line:1 char:88
    + ... ewDrive = "y"; [System.IO.File]::ReadAllText(I:\PostInstall\test.cmd)
    +                                                                         ~
    Unexpected token ')' in expression or statement.
    At line:1 char:1
    + Invoke-Expression ('$OldDrive = "x"; $NewDrive = "y"; [System.IO.File ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ParserError: (:) [Invoke-Expression], ParseException
        + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall,Microsoft.PowerShell.Commands.InvokeExpressionCommand
    
    -DriveLetter was unexpected at this time.
    I:\PostInstall>if ((Get-Partition -DriveLetter $OldDrive -ErrorAction Ignore) -eq $null) {
    I:\PostInstall>
    
     
  10. tempdrive1

    tempdrive1 MDL Member

    Aug 29, 2021
    103
    135
    10
    To me it looks like you are not escaping your quotes properly.
    The PowerShell interpreter processes ReadAllText(I:\PostI, and you can see the path is not a text, as it is not surrounded by quotes.
    Try to be consistent, use single quotes for the wrapper (outermost quoting, right after cmd /C and at the very end), and use double quotes inside.
    Probably could be done better justice, but the error messages seem to show clear indications where the problems comes from: that little ~ below the path for ReadAllText.

    Personally I find it a bit weird you read in a .cmd file, but there are many solutions to a problem in IT, so do whatever you feel like doing.
     
  11. imlost2

    imlost2 MDL Member

    Aug 5, 2013
    149
    159
    10
    #26591 imlost2, Nov 21, 2023
    Last edited: Dec 6, 2023
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. Yanta

    Yanta MDL Senior Member

    May 21, 2017
    477
    274
    10
    The cmd /c is not my code. And yes, I was aware of the issue with quotes. Anyway, I'm not using that code,

    In any case, I think the point is being lost. I should not have posted the code as this has caused the whole thing to go off topic. Can we please ignore the code - my code works fine. It's powershell that's not working.

    The original post, and only issue I'm seeking assistance with is that powershell storage commands don't work on any system for which I've created an image using the MSMG toolkit. If I install a plain vanilla Windows 10 with nothing touched it all works fine.

    So either I removed a component necessary for making powershell cmdlets work, or something else is broken.

    And my question was "What component, if any, needs to be retained for powerchell storage cmdlets to work".
     
  13. tempdrive1

    tempdrive1 MDL Member

    Aug 29, 2021
    103
    135
    10
    Do binary testing, looks like your best option at this point.
    You could be done in a couple of hours.
     
  14. f0ness

    f0ness MDL Novice

    Aug 23, 2019
    18
    7
    0
    Yup.

    I downloaded image 22621.1 from uupdump.
    Using MSMG Toolkit v.13.6, SSU 22621.2567 and KB5032190 (22621.2715) were successfully integrated into the image.

    After that, I removed everything except ClientCBS, CloudExperienceHost, ShellExperienceHost, StartMenuExperienceHost, UndockedDevKit, FirstLogonAnimation, WindowsMediaPlayer,
    Windows Photo Viewer, NotepadApp using the "Remove" menu in the toolkit. And I still get an error when installing Windows.

    So, such a guide really won't hurt.
     
  15. Jingzin

    Jingzin MDL Addicted

    Nov 10, 2021
    666
    532
    30
    Toolkit works great did another 22h2 22621.2283 iso yesterday and last night was installing it. everything works as it should.

    the only real issue theres with the toolkit is that after you install windows and use resetbase, dism scanhealth will throw errors but i found easy fix to fix dism by installing next any update then simply removing it no more dism errors.
     
  16. inTerActionVRI

    inTerActionVRI MDL Expert

    Sep 23, 2009
    1,748
    3,575
    60
    #26596 inTerActionVRI, Nov 22, 2023
    Last edited: Nov 22, 2023
    I asked you if it was a comment block, as the batch code is between:
    <#
    comments here
    #>
    This makes the code unusable in PowerShell, as it turns it into a simple comment block.

    My previous code may contain quotation marks errors, but that's because I didn't know what you were doing, it was a suggestion that didn't work, but OK. I also think there may be something breaking your cmdlet, since the get-partition codes I sent didn't work in native Powershell.

    Have you tried using the code as it was before, but using cmd.exe?
    Code:
    cmd.exe /C "PowerShell.exe -nop Invoke-Expression ('$OldDrive = """"%1""""; $NewDrive = """"%2""""' + [System.IO.File]::ReadAllText('%~f0'))"
    
    or
    Code:
    cmd.exe /C 'PowerShell.exe -nop Invoke-Expression ("""$OldDrive = """"%1""""; $NewDrive = """"%2""""""" + [System.IO.File]::ReadAllText("%~f0"))'
    
    or
    Code:
    cmd.exe /C 'PowerShell.exe -nop Invoke-Expression ("""$OldDrive = """"%1""""; $NewDrive = """"%2""""""" + [System.IO.File]::ReadAllText("""%~f0"""))'
    
    The above code may also contain quotation marks errors. You can try if you want to.

    To avoid using batch script convert the code to powershell using args[] that I suggested. Take this test too.


    I got tired of coding in PowerShell and having to adjust everything for each system. In my codes I only maintain compatibility with native PowerShell 5.1.
     
  17. mhussain

    mhussain MDL Senior Member

    Oct 1, 2012
    368
    144
    10
    hi there
    @inTerActionVRI
    does imck allow you to use a deploied image as the source?
    that is to say,
    I have applied a windows image using dism. can that applied image be used in your wonderful imck?
    thank you for reading my question sir, also thank you for all of the custom developments with imck.
    Majid
     
  18. LordVardus

    LordVardus MDL Novice

    Apr 4, 2018
    35
    6
    0
    Hey, is it possible to remove the Classic Calculator from Windows 10 LTSC 2021 and how does it work with this tool or are there instructions for it?
     
  19. Ace2

    Ace2 MDL Expert

    Oct 10, 2014
    1,869
    1,535
    60
    Yes Calculator can be removed, This list shows what can be removed.
    Code:
    EdgeChromium
    InternetExplorer
    FirstLogonAnimation
    GameExplorer
    LockScreenBackground
    ScreenSavers
    SnippingTool
    SoundThemes
    SpeechRecognition
    Wallpapers
    WindowsMediaPlayer
    WindowsPhotoViewer
    WindowsThemes
    WindowsTIFFIFilter
    WinSAT
    OfflineFiles
    OpenSSH
    RemoteDesktopClient
    RemoteDifferentialCompression
    SimpleTCPIPServices
    TelnetClient
    TFTPClient
    WalletService
    WindowsMail
    AssignedAccess
    CEIP
    FaceRecognition
    KernelDebugging
    LocationService
    PicturePassword
    PinEnrollment
    UnifiedTelemetryClient
    WiFiNetworkManager
    WindowsErrorReporting
    WindowsInsiderHub
    HomeGroup
    MultiPointConnector
    RemoteAssistance
    RemoteDesktopServer
    RemoteRegistry
    WorkFoldersClient
    AccessibilityTools
    Calculator
    DeviceLockdown
    EaseOfAccessCursors
    EaseOfAccessThemes
    EasyTransfer
    FileHistory
    Magnifier
    ManualSetup
    Narrator
    Notepad
    OnScreenKeyboard
    Paint
    ProjFS
    SecurityCenter
    StepsRecorder
    StorageSpaces
    SystemRestore
    WindowsBackup
    WindowsFirewall
    WindowsSubsystemForLinux
    WindowsToGo
    WindowsUpdate
    Wordpad
    AADBrokerPlugin
    AccountsControl
    AddSuggestedFoldersToLibraryDialog
    AppResolverUX
    AssignedAccessLockApp
    AsyncTextService
    BioEnrollment
    CallingShellApp
    CapturePicker
    CBSPreview
    ContentDeliveryManager
    ClientCBS
    CloudExperienceHost
    CredDialogHost
    ECApp
    Edge
    EdgeDevToolsClient
    FileExplorer
    FilePicker
    LockApp
    MapControl
    NarratorQuickStart
    NcsiUwpApp
    OOBENetworkCaptivePortal
    OOBENetworkConnectionFlow
    ParentalControls
    PeopleExperienceHost
    PinningConfirmationDialog
    PrintDialog
    QuickAssist
    RetailDemoContent
    SearchApp
    SettingSync
    ShellExperienceHost
    SkypeORTC
    SmartScreen
    StartMenuExperienceHost
    UndockedDevKit
    WebcamExperience
    WebView2SDK
    Win32WebViewHost
    WindowsDefender
    WindowsMixedReality
    WindowsReaderPDF
    WindowsStoreCore
    XboxCore
    XboxGameCallableUI
    XGpuEjectDialog
    
     
  20. Yanta

    Yanta MDL Senior Member

    May 21, 2017
    477
    274
    10
    It's totally my fault. Sorry.

    I asked a question about the powershell storage commands not working. Then I posted some code that works perfectly, on vanilla PCs. There is no issue with how the code is written.
    I regret posting the code. This caused the whole discussion to shift away from my original question into one of coding techniques. As someone else, posted. there are lots of ways to write code.

    Can we please stop talking about the code. There is nothing wrong with the code.

    The question is "What components must I retain the ensure powershell storage commands work". I asked because an untouched vanilla W10 works perfectly. It's only the images I've created with MSMG that don't work.

    The response was (if I understood it correctly), was to do a "process of elimination", which would take me weeks (Start with full image, remove one component, test, rinse, repeat).

    In the end, I've got new code that uses diskpart and not powershell and works perfectly even on my modified windows images.

    I guess this will just go down in history as unsolvable.

    Yes! Correct! But it's not my code that's breaking powershell storage commands. They are broken in native powershell on ALL PCs. And that's all I wanted to fix.