新建BackUpADLDS.ps1:
$Bdate = Get-Date -Format yyyy-MM-dd$backupPath = "e:\Backup\ADLDS"$InstanceName= "MYADLDS"$numberOfBackupsDaysToKeep = 61#Create a backup of the ADLDS instancedsdbutil "Activate Instance $InstanceName" ifm "Create Full $BackupPath\Temp" quit quitstart-sleep -seconds 600Move-Item $BackupPath\Temp\adamntds.dit $BackupPathRename-Item $BackupPath\adamntds.dit -newname $Bdate"adamntds.dit"cd $BackupPathforfiles.exe -d $numberOfBackupsDaysToKeep -m *.dit -c "cmd /c del /q /f @FILE"exit
执行此PowerShell脚本,会有下面的错误提示:
无法加载文件 ******.ps1,因为在此系统中禁止执行脚本。有关详细信息,请参阅 "get-help about_signing"。
那么要修改about_signing,执行“set-ExecutionPolicy RemoteSigned ”:
执行策略更改
执行策略可以防止您执行不信任的脚本。更改执行策略可能会使您面临 about_Execution_Policies
帮助主题中所述的安全风险。是否要更改执行策略?
[Y] 是(Y)[N] 否(N)[S] 挂起(S)[?] 帮助 (默认值为“Y”): y
新建任务计划, 操作à启动程序à程序或脚本:powershell.exe
添加参数:E:\BackupBAT\BackupADLDS.ps1
新建ADLDS恢复.bat
@echo off:selectset /p continue="请注意adamntds.dit是否在E:\BackUp\ADLDS\adamntds.dit以及确保文件名一样.输入"Y"继续,输入"N"退出."echo %continue%if /i %continue%==n goto :eof else (if /i %continue%==y goto ldsrestore else (echo 您的输入不正确,请重新输入!&goto select)):ldsrestorenet stop CJADLDSecho A| xcopy /os E:\BackUp\ADLDS\adamntds.dit "C:\Program Files\Microsoft ADAM\CJADLDS\data\adamntds.dit"net start CJADLDSexit