/build/static/layout/Breadcrumb_cap_w.png

KACE SMA Change Hostname PC Scripting

Hi Ninja!

Does anyone know the scripting to change the hostname on the device?

In this case, the devices are joined to the AD domain, I think there is an AD policy that blocks the scripting. Is there any special treatment for scripting? 

Because if I try it on a device that is not joined to the domain, it works. Here is the script:

wMXi2K7MqLiSAAAAABJRU5ErkJggg==

And this is the contents of the .ps1 file

QFpHhnsywAAAABJRU5ErkJggg==


Hope someone can help me, thanks a lot!


0 Comments   [ + ] Show comments

Answers (1)

Posted by: sven.hain 1 month ago
Third Degree Green Belt
2

Hi, I tried it in my lab and probably see where the issue is. Do you run this script as Local System or with a specified user? If you run it as Local System it does not work because of the domain join, Windows expect you to change it with a user that has the necessary permissions in your AD. Also notice, that an active connection to the domain must be there in order to change the device name. Try to run it with a service account that has the permissions to change device names in your AD and see if it works better.

I also ran your script as Online Shell script, you do not have to create a task and run it under the powershell since we support it natively as well.

jk23UFFFBAAQUUUEABBRRQQAEFFFBAAQXqIWDoWA9Vt6mAAgoooIACCiiggAIKKKCAAgoooEATCxg6NvHJt+sKKKCAAgoooIACCiiggAIKKKCAAgrUQ8DQsR6qblMBBRRQQAEFFFBAAQUUUEABBRRQQIEmFjB0bOKTb9cVUEABBRRQQAEFFFBAAQUUUEABBRSoh4ChYz1U3aYCCiiggAIKKKCAAgoooIACCiiggAJNLGDo2MQn364roIACCiiggAIKKKCAAgoooIACCihQDwFDx3qouk0FFFBAAQUUUEABBRRQQAEFFFBAAQWaWMDQsYlPvl1XQAEFFFBAAQUUUEABBRRQQAEFFFCgHgKGjvVQdZsKKKCAAgoooIACCiiggAIKKKCAAgo0sYChYxOffLuugAIKKKCAAgoooIACCiiggAIKKKBAPQQMHeuh6jYVUEABBRRQQAEFFFBAAQUUUEABBRRoYgFDxyY++XZdAQUUUEABBRRQQAEFFFBAAQUUUECBeggYOtZD1W0qoIACCiiggAIKKKCAAgoooIACCijQxAKGjk188u26AgoooIACCiiggAIKKKCAAgoooIAC9RAwdKyHqttUQAEFFFBAAQUUUEABBRRQQAEFFFCgiQUMHZv45Nt1BRRQQAEFFFBAAQUUUEABBRRQQAEF6iFg6FgPVbepgAIKKKCAAgoooIACCiiggAIKKKBAEwv8H4pBfyOqngwDAAAAAElFTkSuQmCC


Comments:
  • Hi Sven,
    Thanks for the advice!

    I've tried it and here are the logs that appear:
    C:\ProgramData\Quest\KACE\scripts\58\Changehostname.ps1 : File
    C:\ProgramData\Quest\KACE\scripts\58\Changehostname.ps1 cannot be loaded because running scripts
    is disabled on this system. For more information, see about_Execution_Policies at
    https:/go.microsoft.com/fwlink/?LinkID=135170.
    At line:1 char:1
    + C:\ProgramData\Quest\KACE\scripts\58\Changehostname.ps1
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess


    I'm pretty sure I've used admin credentials that have the priviledge to change the hostname. - Nzw 1 month ago
    • I've tried adding commands based on this link:
      1. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4
      2. https://stackoverflow.com/questions/64633727/how-to-fix-running-scripts-is-disabled-on-this-system

      but it still doesn't work - Nzw 1 month ago
    • Based on this, try adding the following line at the very beginning of your script:
      set-ExecutionPolicy Bypass -Force

      This should allow your script to run. - sven.hain 1 month ago
      • tried it but it's still the same

        Output Log
        C:\ProgramData\Quest\KACE\scripts\58\hostname.ps1 : File
        C:\ProgramData\Quest\KACE\scripts\58\hostname.ps1 cannot be loaded because running scripts is
        disabled on this system. For more information, see about_Execution_Policies at
        https:/go.microsoft.com/fwlink/?LinkID=135170.
        At line:1 char:1
        + C:\ProgramData\Quest\KACE\scripts\58\hostname.ps1
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : SecurityError: (:) [], PSSecurityException
        + FullyQualifiedErrorId : UnauthorizedAccess - Nzw 1 month ago
      • Do you maybe have group policies in place that configure the execution policies? You can see a guide on which settings is needed in the first link you posted earlier. - sven.hain 1 month ago
      • Hi Sven,

        I change the execution policies manually on my client device, and the change hostname works!

        Just curious, can the change execution policies be run automatically through the sma kace script and one script with the change hostname?

        If the script is like this, is it possible?
        Set-ExecutionPolicy RemoteSigned -Force

        # Define the new hostname
        $newHostname = "DIV-TIS-003"

        # Get the current hostname
        $currentHostname = (Get-WmiObject Win32_ComputerSystem).Name

        # Check if the hostname needs to be changed
        if ($currentHostname -ne $newHostname) {
        # Rename the computer
        Rename-Computer -NewName $newHostname -Force

        # Inform the user
        Write-Host "Hostname has been changed from $currentHostname to $newHostname."

        # Restart the computer to apply the change
        Restart-Computer -Force
        } else {
        Write-Host "The hostname is already set to $newHostname."
        } - Nzw 1 month ago
      • That should work yes. Otherwise setup a group policy if possible to set it automatically to RemoteSigned for exmaple. - sven.hain 1 month ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ