一旦应用了 DSC 配置,是否可以从计算机中删除它?
例如,我有一个configuration
块如下:
configuration SevenZip {
Script Install7Zip {
GetScript = {
$7ZipFolder = '{0}\7-Zip' -f $env:ProgramFiles;
$Result = @{
Result = '';
}
if (Test-Path -Path $7ZipFolder) {
$Result.Result = 'Present';
}
else {
$Result.Result = 'Nonpresent';
}
Write-Verbose -Message $Result.Result;
$Result;
}
SetScript = {
$7ZipUri = 'http://colocrossing.dl.sourceforge.net/project/sevenzip/7-Zip/9.20/7z920-x64.msi';
$OutputFile = '{0}\7-Zip.msi' -f $env:TEMP;
Invoke-WebRequest -Uri $7ZipUri -OutFile $OutputFile;
Write-Verbose -Message ('Finished downloading 7-Zip MSI file to {0}.' -f $OutputFile);
$ArgumentList = '/package "{0}" /passive /norestart /l*v "{1}\Install 7-Zip 9.20 64-bit.log"' -f $OutputFile, $env:TEMP;
$Process = Start-Process -FilePath msiexec.exe -ArgumentList $ArgumentList -Wait -PassThru;
Write-Verbose -Message ('Process finished with exit code: {0}' -f $Process.ExitCode);
Remove-Item -Path $OutputFile;
Write-Verbose -Message ('Removed MSI file: {0}' -f $OutputFile);
}
TestScript = {
$7ZipFolder = '{0}\7-Zip' -f $env:ProgramFiles;
if (Test-Path -Path $7ZipFolder) {
$true;
}
else {
$false;
}
}
}
}
如果未找到应用程序,此配置块将生成一个 MOF,该 MOF 使用Script
资源在应用它的系统上安装 7-Zip 9.20 64 位。
应用此配置后,使用以下命令,如果不再需要 7-Zip ,如何将其从系统中删除?
SevenZip -OutputPath c:\dsc\7-Zip;
Start-DscConfiguration -Wait -Path C:\dsc\7-Zip -Verbose;