Procedure to popup for input (on administrator running the procedure)

Hello. Is there a way to have a procedure within Xcitium Enterprise that when it is run, pops up request for input (aka username ) that will then take that input done on the admin side and enter the data into the procedure script? I have done it in powershell but it runs on remote computer screen and if I embed into Xcitium powershell it will just fail and due to no input.

hi @mphillips

I will check with the concern team for feasibility and get back to you.

Hi @mphillips ,

Our script developer wants to know the use case of the script, as we are not clear on how you want the username you got as input in the script, and how they they are going to be used in script .

Kind Regards,
PremJK

Use case for the script is to use scanstate and loadstate from USMT to copy profiles. I have a powershell script that I can run directly on a user computer which will then pop up and ask for what profile I want to backup by entering in the user ID. I also have another script that asks for the same info but directly within powershell itself when run from a powershell screen. I have been running that by using Xcitium - remote connection - powershell and manually pointing to the PS1 file and when it asks within the command window to then enter in the username. What I am looking to have is the ability to have this as a Xcitium procedure that runs as a powershell (since that is what I have it programmed as) but pops up prompt on MY computer for me to input data that then enters the username into the procedure to run against the computer I am running that procedure against. I want to be able to run the procedure from my computer, through the portal against the remote computer specifying the account to back up to make it easier for some of our techs to use instead of having to go into the remote session and run remote powershell via xcitium

Currently I run this script (server names removed) manually via powershell within xcitium.

PowerShell script to prompt for username and use scanstate.exe for account backup

Prompt for username

$username = Read-Host -Prompt “Enter Username to Back Up”

Check if the user provided a username

if ($username -ne “”) {
# Construct the scanstate.exe command with the provided username
$scanstateCommand = “$serverPath \servername\ProfileBackup\usmt\scanstate.exe \servername\ProfileBackup\Profiles$username /i:\servername\ProfileBackup\usmt\MigUser.xml /o /ue:** /ui:$username”

# Execute the scanstate.exe command
Invoke-Expression -Command $scanstateCommand

Write-Host "Backup completed for user: $username"

} else {
Write-Host “No username provided. Backup process aborted.”
}
Pause

If the question is how you can run an Xcitium script to run powershell with a popup, here is starter code:

#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name
import os
import subprocess
import tempfile
home_dir = os.path.expanduser("~")


#############
# CREATE POWERSHELL FILE WITH NEEDED COMMANDS
#############

PowershellFile = '''
# Prompt for input using Read-Host
Add-Type -AssemblyName System.Windows.Forms

# Create a form
$form = New-Object Windows.Forms.Form
$form.Text = "Input"
$form.Size = New-Object Drawing.Size @(300, 165)
$form.AcceptButton = $okButton  # Set the default button to OK

# Create a label
$label = New-Object Windows.Forms.Label
$label.Location = New-Object Drawing.Point @(10, 30)
$label.Size = New-Object Drawing.Size @(280, 20)
$label.Text = "Enter a value:"
$form.Controls.Add($label)

# Create a text box
$inputBox = New-Object Windows.Forms.TextBox
$inputBox.Location = New-Object Drawing.Point @(10, 60)
$inputBox.Size = New-Object Drawing.Size @(260, 20)
$form.Controls.Add($inputBox)

# Create an OK button
$okButton = New-Object Windows.Forms.Button
$okButton.Location = New-Object Drawing.Point @(10, 90)
$okButton.Size = New-Object Drawing.Size @(120, 30)
$okButton.Text = "OK"
$okButton.DialogResult = [Windows.Forms.DialogResult]::OK
$form.Controls.Add($okButton)

# Create a Cancel button
$cancelButton = New-Object Windows.Forms.Button
$cancelButton.Location = New-Object Drawing.Point @(140, 90)
$cancelButton.Size = New-Object Drawing.Size @(120, 30)
$cancelButton.Text = "Cancel"
$cancelButton.DialogResult = [Windows.Forms.DialogResult]::Cancel
$form.Controls.Add($cancelButton)

# Show the form and wait for user input
$result = $form.ShowDialog()

# Check if the user clicked OK
if ($result -eq [Windows.Forms.DialogResult]::OK) {
    $inputValue = $inputBox.Text
    # Display the input value in a popup
    [System.Windows.Forms.MessageBox]::Show("You entered: $inputValue", "Result", "OK", "Information")
} else {
    [System.Windows.Forms.MessageBox]::Show("You clicked Cancel. Exiting script.", "Information", "OK", "Information")
}

# Dispose of the form
$form.Dispose()
'''

#############
# EXECUTE POWERSHELL FILE
#############

def ExecuteCMD(CMD, OUT=False):
    import ctypes

    class DisableFileSystemRedirection:
        _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
        _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection

        def __enter__(self):
            self.old_value = ctypes.c_long()
            self.success = self._disable(ctypes.byref(self.old_value))

        def __exit__(self, type, value, traceback):
            if self.success:
                self._revert(self.old_value)

    with DisableFileSystemRedirection():
        process = subprocess.Popen(CMD, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()
        ret = process.returncode

    if ret == 0:
        if stdout:
            print("CMD output:", stdout.decode('utf-8').strip())
        else:
            print("CMD created successfully: " + CMD)
    else:
        if stderr:
            print("Error creating CMD:", stderr.decode('utf-8').strip())
        else:
            print("Returned non zero value")

#############
# MAIN PROCEDURE
#############

if __name__ == "__main__":
    fileToCreate = 'runpowershell.ps1'
    # Define the file path for the PowerShell script
    FILEPATH = os.path.join(os.environ['TEMP'], fileToCreate)
	ppath=FILEPATH.replace("\\","/") #r'C:\Users\Comprise\AppData\Local\Temp\runpowershell.ps1' #Define Powershell file path
    print("POWERSHELL ppath:", ppath)

    with open(FILEPATH, 'w') as f:
        f.write(PowershellFile)

    # Check if the file was created successfully
    if os.path.exists(FILEPATH):
    
        CMD='PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& "%s""'%(ppath)
        import os
        import ctypes
        import subprocess
        class disable_file_system_redirection:
            _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
            _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
            def __enter__(self):
                self.old_value = ctypes.c_long()
                self.success = self._disable(ctypes.byref(self.old_value))
            def __exit__(self, type, value, traceback):
                if self.success:
                    self._revert(self.old_value)
        with disable_file_system_redirection():
            ping = subprocess.Popen(CMD,stdout=subprocess.PIPE,stderr = subprocess.PIPE,shell=True)
            out = ping.communicate()[0]
            output = str(out)
            print output
            print"Powershell file executed successfully"
    else:
        print("Failed to create the POWERSHELL file to the temp folder.")

Hi @mphillips ,

We have a script request with our script developer and ticket ID: CS-52861 for your reference.

Kind Regards,
PremJK

Hi @mphillips ,

We have shared the script prepared by our developer with instruction to be followed as a private message to your inbox. Please check and let us know if you need any modifications.

Kind Regards,
PremJK