应用后,是否可以从计算机中删除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;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Script如果找不到应用程序,此配置块将生成一个MOF,该MOF使用资源在应用它的系统上安装7-Zip 9.20 64位.
一旦应用了此配置,使用以下命令,如果不再需要7-Zip ,如何从系统中删除它?
SevenZip -OutputPath c:\dsc\7-Zip;
Start-DscConfiguration -Wait -Path C:\dsc\7-Zip -Verbose;
Run Code Online (Sandbox Code Playgroud)
要将7zip安装移出范围,可以应用另一个未指定7zip的配置.配置不会"回滚",所以,如果已安装,它将保持安装状态.如果以后删除它,将不会重新安装.
您也可以使用手动路由并从c:\ windows\system32\configuration中删除配置文档.您需要删除Current.mof,backup.mof以及可能的Previous.mof.
Remove-DscConfigurationDocument可以解决这个问题 https://technet.microsoft.com/en-us/library/mt143544.aspx
Remove-DscConfigurationDocument cmdlet从DSC配置存储中删除配置文档(.mof文件).在配置期间,Start-DscConfiguration cmdlet将.mof文件复制到目标计算机上的文件夹中.此cmdlet删除该配置文档并执行其他清理.
小智 5
史蒂文是对的。当我运行这个:
删除项目 C:\Windows\System32\Configuration\Current.mof, C:\Windows\System32\Configuration\backup.mof, C:\Windows\System32\Configuration\Previous.mof
现在 Get-DscConfiguration 返回与干净机器相同的错误:
Get-DscConfiguration :当前配置不存在。首先启动 DSC 配置以创建当前配置。
这就是我一直在寻找的。我知道它不会恢复配置。我只是想“撤消”正在应用的配置。
谢谢!