Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 验证批处理文件中的命令是否成功,或恢复所有设置_Powershell_Batch File_Vbscript_Server - Fatal编程技术网

Powershell 验证批处理文件中的命令是否成功,或恢复所有设置

Powershell 验证批处理文件中的命令是否成功,或恢复所有设置,powershell,batch-file,vbscript,server,Powershell,Batch File,Vbscript,Server,请检查我的批处理文件命令,因为我需要从旧域断开计算机并将其连接到新域 有时计算机成功地退出计算机,但未能将其添加到新域中,因此此计算机将处于域外。我需要添加命令来验证计算机是否成功加入到新域,否则将其恢复到旧域 @echo关闭 netdom.exe删除%computername%/域:MyOlddomain.local/UserD:Myusername/PasswordD:Mypassword Ping 127.0.0.1-n5>nul netdom.exe加入%computername%/域:

请检查我的批处理文件命令,因为我需要从旧域断开计算机并将其连接到新域

有时计算机成功地退出计算机,但未能将其添加到新域中,因此此计算机将处于域外。我需要添加命令来验证计算机是否成功加入到新域,否则将其恢复到旧域

@echo关闭
netdom.exe删除%computername%/域:MyOlddomain.local/UserD:Myusername/PasswordD:Mypassword
Ping 127.0.0.1-n5>nul
netdom.exe加入%computername%/域:MyNewDomain/UserD:Myusername/PasswordD:Mypassword
Ping 127.0.0.1-n5>nul
关闭-t 5-r-f

最好的方法是使用IF语句

IF语句的基本结构如下所示

IF EXIST "%1" (
    echo "it's here!"
) ELSE (
    echo "it isn't here!"
)
这样做将允许您在需要时恢复。

这个问题与PowerShell或VBScript有什么关系?您是否尝试在删除操作后检查errorlevel?请详细说明OP应如何使用
if
语句验证域加入是否失败。