Script Not Executed as Expected After Deployment

Script Not Executed as Expected After Deployment

Possible Causes

  1. The script file name must be install.bat
  2. When only a single script file needs to be delivered, it must still be placed inside a folder and then the folder should be compressed into a zip file
  3. The script must add a self-delete logic at the end, otherwise repeated deployments may fail. See Examples A and B below.
  4. If issues persist, please contact us by WeChat or email:  support@nubiscloud.io

Example A — Rename Computer Script

install.bat (Click to expand/collapse)
@echo off  
REM Directly execute the PowerShell script  
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0rename-computer.ps1"                   
rename-computer.ps1 (Click to expand/collapse)
# Get the directory where the script resides
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition

# Build the paths to delete
$batPath = Join-Path $scriptDir 'install.bat'
$ps1Path = $MyInvocation.MyCommand.Definition  # This script itself

# Delete install.bat and this script (ignore not found/permission errors) before reboot
Remove-Item -Path $batPath -Force -ErrorAction SilentlyContinue
Remove-Item -Path $ps1Path -Force -ErrorAction SilentlyContinue

# Rename and reboot (this command triggers a reboot; put it last)
Rename-Computer -NewName 'PCCN1003' -Restart -Force         

Example B — Log Collection Script

install.bat (Click to expand/collapse)
@echo off
setlocal enabledelayedexpansion

:: Use the computer name as the identifier
set "sn=%computername%"

:: Get timestamp (yyyyMMdd_HHmmss)
for /f "delims=" %%a in ('wmic os get localdatetime ^| find "."') do (
    set "now=%%a"
    set "datetime=!now:~0,8!_!now:~8,6!"
)
set "NOW_STR=%datetime%"
set "PREFIX=%sn%_%NOW_STR%_"
set "TARGET_DIR=D:\logs_backup\%sn%_%NOW_STR%"

:: Create the target folder
if not exist "%TARGET_DIR%" (
    mkdir "%TARGET_DIR%"
)

:: Copy all txt files under C:\ProgramData\OraService...
for %%F in (C:\ProgramData\OraService\*.txt) do (
    copy /Y "%%F" "%TARGET_DIR%\%PREFIX%%%~nxF" >nul
)

rem ===== Self-delete: call Delete-Self.ps1 in the same directory =====
set "deleteScript=%~dp0Delete-Self.ps1"
if exist "%deleteScript%" (
  powershell -NoProfile -ExecutionPolicy Bypass -Command ^
    "Start-Process PowerShell -WindowStyle Hidden -ArgumentList '-NoProfile','-ExecutionPolicy','Bypass','-File','\"\"%deleteScript%\"\"'"
)

endlocal
Delete-Self.ps1(Click to expand/collapse)
# Delete-Self.ps1
# After the main batch exits, delete install.bat and this script itself
Start-Sleep -Seconds 2

$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$batPath   = Join-Path $scriptDir 'install.bat'
$ps1Path   = $MyInvocation.MyCommand.Definition

# Delete install.bat
Remove-Item -Path $batPath -Force -ErrorAction SilentlyContinue
# Delete itself
Remove-Item -Path $ps1Path -Force -ErrorAction SilentlyContinue
    • Related Articles

    • Network Requirements for Remote Desk (VNC)

      Q: What are the recommended network conditions for using the remote desk (VNC) feature in Nubis? A: To ensure a smooth and responsive experience when using the Nubis remote desk function (VNC), we recommend that the device's network environment meets ...