Hello Jay,
Microsoft does not recommend renaming computers joined to an AD domain remotely. For example, in the description of the Rename method of the Win32_ComputerSystem class that is used in the script it is clearly stated that "... you cannot use the method remotely for domain computers". For details, see http://msdn.microsoft.com/en-us/library ... 85%29.aspx. For this purpose, we decided not to provide the Rename functionality for computers in Adaxes.
However, if you want to go with the script that you provided, you can, for example, create a Business Rule that calls the script after modifying a certain property of the computer in Adaxes. The Business Rule will set the computer name to the value of the property with the help of the script. For this purpose, you can use one of Adaxes virtual properties, for example, CustomAttributeText1. Such properties are not stored in AD, but you can use them as any other properties of AD objects. To create such a Business Rule:
-
Create a new Business Rule.
-
On the 2nd step of the Create Business Rule wizard, select Computer and After Updating a Computer.
-
On the 3rd step, add the Run a program or PowerShell script action and paste the following script in the Script field:
Get-WmiObject Win32_ComputerSystem -ComputerName '%cn%' -Authentication 6 | ForEach-Object {$_.Rename('%adm-CustomAttributeText1%', $Context.RunAs.UserName, $Context.RunAs.Password)}
Get-WmiObject Win32_OperatingSystem -ComputerName '%cn%' | ForEach-Object {$_.Win32Shutdown(6)}
-
The script requires credentials of a user with sufficient permissions to change a computer name. The credentials are passed to the script from the Run As parameters of the action. To provide the credentials:
- Switch the radio button in the Run as section to This account.
- Click the associated Specify button and specify the credentials.
-
Enter a short description for the script and click OK.
-
Right-click the action and click Add Condition.
-
Select the If <property> changed condition.
-
Expand the <property> drop-down list.
-
Select the CustomAttributeText1 property.
-
Select has changed.
-
Click OK and finish creation of the Business Rule.
Now, whenever you change the value of the CustomAttributeText1 property for a computer, the Business Rule will launch the script and will try to rename the computer to the name that you specified in the CustomAttributeText1 property.