The term 'gactuil' is not recognized as the name of a cmdlet

I have a simple function that I wrote to uninstall assembly for GAC on my windows 8 machine.

I get error saying ‘gacutil’ is not recognized as the name. Relatively new to powershell. I am using it as needed. Any suggestions please?

 function Uninstall($assemblyName) 
{

    Write-Host "in the function Uninstall"

   $ret = gacutil /u $assemblyName

   if($ret -like "*Number of assemblies uninstalled = 1*")
   {
      return $true
   }

   return $false
}

Unless the binary is in the Path environment variable, you will need to specify the full path to the executable. :slight_smile:

If I put the full path like below, it doesn’t like it because the folder names have spaces in them.

I tried putting in double quotes. but it didn’t work either. Any suggestions please?

$ret = C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe /u $assemblyName

I tried the following. It still says can’t recognize gacutil.exe

function Uninstall($assemblyName) 
{

    Write-Host "in the function"

    $gacutilpath = "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe /u "

   $ret = $gacutilpath + " " +  $assemblyName

   Write-Host $ret

   if($ret -like "*Number of assemblies uninstalled = 1*")
   {
      return $true
   }

   return $false
}

Oh, right, of course. Okay, so what you need here isn’t super obvious, but let me explain briefly:

PowerShell will see that as just any old string object. It doesn’t know to execute it like it might with a regular path or filename (it tries to be helpful there, with some success, depending).

To get it to execute what it might find at a path you’ve made into a string (which you kinda have to here), you have a few options:

# Simplest
& "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe /u $AssemblyName"

# Alternative, bit easier to control if you need to, bit easier to work with multiple arguments.
Start-Process -Wait -FilePath "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe" -ArgumentList '/u', $AssemblyName

I used Start-Process suggestion.

Not working still

https://stackoverflow.com/questions/50032403/start-process-cmdlet-with-argumentlist-throw-invalid-argument-error

I recommned for you to take a small step back and start from scratch with learning the very basics of Powershell.
Here you can find some great sources to start with: Beginner Sites and Tutorials.