1

Not sure if this is for stakoverflow or serverfault.

I am deploying a Powershell script using MS Intune. The script works when run locally, but when deployed I get the error below:

Remove-LocalGroupMember : The term 'Remove-LocalGroupMember' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Program Files (x86)\Microsoft Intune Management

I am not sure why this commandlet is unavailable as it is definitely there if I open a powershell and run this command.

I am logging the $user variable to check that it is not null or running under a different context.

The code is quite simple as below:

$user = $(whoami)

$user | Out-File 'C:\powershelllog.log'

Remove-LocalGroupMember -Group Administrators -Member $user
7
  • the module that cmdlet is in was added with ps5.1 and does not exist in 5.0 or earlier. do you have that module on the device in question? this >>> Microsoft.PowerShell.LocalAccounts — learn.microsoft.com/en-us/powershell/module/… <<< Commented Aug 20, 2019 at 12:38
  • Yes, on the local computer, I open Powershell and then start typing the command and press tab, then it comes out. I can run the script locally on the computer. Commented Aug 20, 2019 at 14:26
  • when you say "local computer" do you mean the one that intune is targeting or the one that you are coding on?. also ... the module may not be in the path that the intune stuff is using. have you tried adding code to verify that the module is visible to intune on that system? Commented Aug 20, 2019 at 14:58
  • Intune is deploying a script, it runs under the context of the logged on user. It doesn't work through Intune, if I run it locally as in the same script is saved on the C drive and I run it from there then it works. Commented Aug 20, 2019 at 16:03
  • I have set the script to dump the output of get-command to the log file and the weird thing is that it doesn't have the command listed when done from Intune, but it does if I run get-command locally. I need to know why this is? It's not making sense to me. Commented Aug 20, 2019 at 16:04

1 Answer 1

0

I believe I've run into the same issue as you are having. I've been trying to create a local admin account on machines. Running the powershell script with the system context in Intune. What I've found is that you must check: "Run script in 64 bit PowerShell Host" inside of the Intune where you import powershell scripts.

Apparently not all commands are available with the 32 bit ps console running that way.

I also used the get-command to determine what module the command that was reporting not found was is in, and used the import-module at the top of my script in case.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I will look for this next time I am logged into Azure. In the end I used WMI embedded within the PS script instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.