Problems with Powershell and CLSID and -ComObject

lupinlicious 136 Reputation points
2022-01-11T08:59:14.45+00:00

Hello,

When I try to run a script (from another computer this time) I got the following error (I only removed IP-adress)

163816-image.png

I read about that might cause by Office? So I have installed 64bit on a 64bit Windows server. Otherwise I'm using the same Office installation at home.

Even if it says that F21ABCD already exists on the folder \Computers\ I can still proceed with the installation

The script:

function Set-OSDComputerName {  
  
     $ErrorProvider.Clear()  
     $lastFour = $TBComputerName.text.substring($TBComputerName.text.length -4,4) # Get the last 4 caharcters of computer name  
     $badstring = select-string -path "\\IP\DS\bad_words.txt" -pattern $lastfour  
   
    if ($badstring) {  
            $ErrorProvider.SetError($GBComputerName, "Computer name cannot be more than 6 characters")  
                return  
                }  
     if ($TBComputerName.Text.Length -eq 0) {  
            $ErrorProvider.SetError($GBComputerName, "Please enter a computer name")  
                return  
                }  
    if ($TBComputerName.Text.Length -gt 7) {  
            $ErrorProvider.SetError($GBComputerName, "Computer name cannot be more than 6 characters")  
                return  
                }  
    if ($TBComputerName.Text -notmatch '^[F][0-9]{2,2}[a-zA-Z]{4,4}$') {  
           $ErrorProvider.SetError($GBComputerName, "Computer name must be named with <F> and <numbers> and <four random letters>")  
               return  
               }    
    if ($badstring) {  
           $ErrorProvider.SetError($GBComputerName, "Please enter a computer name")  
               return  
               }                           
             else {                         
                $OSDComputerName = $TBComputerName.Text -replace "[\[\]:;|=+*?<>\/,]+", ''  
                    $temp_file = $temp_path + $OSDComputerName + ".txt"  
    
    if (Select-String -Path "\\IP\DS\bad_words.txt" -Pattern $TBComputerName.text.substring($TBComputerName.text.Length - 4, 4)) {  
          $ErrorProvider.SetError($GBComputerName, "Computer name contains a bad word, not acceptable")  
             return  
              }  
                 else {         
                     New-Item -Path "\\IP\DS\Computers\$OSDComputerName" -ItemType File | Out-Null  
                     $ErrorProvider.SetError($GBComputerName, "Computer name contains a bad word, not acceptable")  
                 }  
                 $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment   
                 $TSEnv.Value("OSDComputerName") = "$($OSDComputerName)"  
                 $Form.Close()  
             }  
             }  
Windows for business Windows Client for IT Pros Devices and deployment Set up, install, or upgrade
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2022-01-11T17:52:03.087+00:00

    Hi @lupinlicious ,

    in your script in line 7 and in line 23 you have the $badstring in your if condition. Why?
    In line 4 to 5 you are doing the same if condition like in line 31. Why?

    How does your script looks now (after your troubleshooting)?

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


2 additional answers

Sort by: Most helpful
  1. lupinlicious 136 Reputation points
    2022-01-11T09:00:12.423+00:00

    The registry is showing me the following value: {00020832-0000-0000-C000-000000000046} in Computer\HKEY_CLASSES_ROOT\Excel.Addin\CLSID

    Computer\HKEY_CLASSES_ROOT\Wow6432Node\CLSID
    Default (value not set) and CLBVersion 0x00000007

    0 comments No comments

  2. lupinlicious 136 Reputation points
    2022-01-11T16:31:01.99+00:00

    I manage to solved it, unfortunely I don't know what might caused it.

    I troubleshooted each line, had them removed and rebuiled everything.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.