Skip to content

Commit

Permalink
Update dism.ps1
Browse files Browse the repository at this point in the history
--ci
  • Loading branch information
linianhui committed Oct 20, 2024
1 parent 78fa8e8 commit dcd9ccd
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/powershell/script/dism.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,49 @@

function Dism-Backup-Os {
param (
[string] $SourceDriver = 'c',
[string] $TargetDriver = 'd'
[string] $SourcePath = 'c:\',
[string] $TargetPath = 'f:\_backup\'
)

[string]$OsName= Dism-Get-OsName;
[string]$OsName = Dism-Get-OsName;
[string]$Date = $(Get-Date -Format 'yyyy-MM-dd');
[string]$Name = "${OsName}-${Date}".ToLower();
$COMMAND = "DISM /Capture-Image /CaptureDir:${SourceDriver}:\ /Name:${Name} /ImageFile:${TargetDriver}:\${Name}.wim";
Log-Debug "$COMMAND";
$COMMAND | Out-File -FilePath "${TargetDriver}:\dism-${Name}.bat"
[string]$ImageFile = "${TargetPath}${OsName}.wim";

$CaptureImageCommand = "DISM /Capture-Image /CaptureDir:${SourcePath} /Name:${Name} /ImageFile:${ImageFile}";
$GetImageCommand = "DISM /Get-ImageInfo /ImageFile:$ImageFile";
$BatFilePath = "d:\dism-${OsName}.bat";

$CaptureImageCommand | Out-File -FilePath $BatFilePath
$GetImageCommand | Out-File -Append -FilePath $BatFilePath
Get-Content -Path $BatFilePath
}

function Dism-Backup-Os-Append {
param (
[string] $SourcePath = 'c:\',
[string] $ImageFile
)
$GetImageCommand = "DISM /Get-ImageInfo /ImageFile:$ImageFile";

[string]$OsName = Dism-Get-OsName;
[string]$Date = $(Get-Date -Format 'yyyy-MM-dd');
[string]$Name = "${OsName}-${Date}".ToLower();

$AppendCommand = "DISM /Append-Image /CaptureDir:${SourcePath} /Name:${Name} /ImageFile:$ImageFile";
$BatFilePath = "d:\dism-${OsName}-append.bat";

$GetImageCommand | Out-File -FilePath $BatFilePath
$AppendCommand | Out-File -Append -FilePath $BatFilePath
$GetImageCommand | Out-File -Append -FilePath $BatFilePath
Get-Content -Path $BatFilePath
}

function Dism-Get-Image-Info {
param (
[string] $ImageFile
)
DISM /Get-ImageInfo /ImageFile:$ImageFile
}

function Dism-Get-Intl {
Expand All @@ -30,6 +63,6 @@ function Dism-Get-Lang {
function Dism-Get-OsName {
$ComputerInfo = Get-ComputerInfo;
[string]$CsName = $ComputerInfo.CsName.Trim().ToLower();
[string]$OsName = $($($ComputerInfo.OsName.ToLower() -Replace 'microsoft','').Trim() -Replace ' ', '-');
[string]$OsName = $($($ComputerInfo.OsName.ToLower() -Replace 'microsoft', '').Trim() -Replace ' ', '-');
return "${CsName}-${OsName}";
}

0 comments on commit dcd9ccd

Please sign in to comment.