taypatte Posted September 20, 2019 Posted September 20, 2019 I am editing a program written by a colleague that is used to name computers during imaging. I work in education, so it is used to name computers in schools a certain format. However, he asked me to find a way to display the current machine name from SCCM because he wants to see what the name is before he replaces it with the new name. My problem is, I cannot get the function I have to work: Func GetMachineName() $oTaskSequence = ObjCreate("Microsoft.SMS.TSEnvironment") $oTaskSequence("_SMSTSMachineName") = $computerName GUICtrlSetData($txtComputerName,$computerName) EndFunc I have scoured every forum and every search online and this is the way everyone says to do it and I cannot find any other solution. I can get @ComputerName to work, but that doesn't work with SCCM right? Help is much appreciated!
Subz Posted September 20, 2019 Posted September 20, 2019 Assume you have a Gui in another function? To get the variable you would use something like, to change the computer name you would need to update the OSDComputerName variable. $computerName = $oTaskSequence("_SMSTSMachineName")
taypatte Posted September 20, 2019 Author Posted September 20, 2019 I have done that before and get the error "Variable cannot be accessed in this manner.: $computerName = $oTaskSequence("_SMSTSMachineName") $computerName = $oTaskSequence^ ERROR And yes I do have a GUI already in place.
taypatte Posted September 20, 2019 Author Posted September 20, 2019 8 minutes ago, Subz said: Assume you have a Gui in another function? To get the variable you would use something like, to change the computer name you would need to update the OSDComputerName variable. $computerName = $oTaskSequence("_SMSTSMachineName") I have done that before and get the error "Variable cannot be accessed in this manner.: $computerName = $oTaskSequence("_SMSTSMachineName") $computerName = $oTaskSequence^ ERROR And yes I do have a GUI already in place.
Subz Posted September 20, 2019 Posted September 20, 2019 Try OSDComputerName rather than _SMSTSMachineName, also add a check IsObj($oTaskSequence) after creating the object.
taypatte Posted September 20, 2019 Author Posted September 20, 2019 3 minutes ago, Subz said: Try OSDComputerName rather than _SMSTSMachineName, also add a check IsObj($oTaskSequence) after creating the object. Turns out $oTaskSequence is not being created as an object, which explains it.
Subz Posted September 20, 2019 Posted September 20, 2019 Is your WinPE environment 32 or 64 bit? If it's 64-bit then have you tried compiling the script as 64 bit?
taypatte Posted September 20, 2019 Author Posted September 20, 2019 1 minute ago, Subz said: Is your WinPE environment 32 or 64 bit? If it's 64-bit then have you tried compiling the script as 64 bit? It is 64 bit and yes I have compiled it as 64 bit, as I figured that was the problem before.
Subz Posted September 20, 2019 Posted September 20, 2019 Strange that you can rename the machine because that would imply creating the object would work? Personally only ever used this method with vbscript, have you tried writing a vbscript or a vbscript that can output the computername and then call this from your Autoit script?
taypatte Posted September 20, 2019 Author Posted September 20, 2019 Just now, Subz said: Strange that you can rename the machine because that would imply creating the object would work? Personally only ever used this method with vbscript, have you tried writing a vbscript or a vbscript that can output the computername and then call this from your Autoit script? I have thought about it, but I have no experience with VBScript so I've been trying to avoid it, but I think I'll have to do it in the end.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now