Sorry for the long response time. I had some other issues that took precedence but I have some more information now.
As for the above suggestions running as x86/x64 should not impact the use case here and I have already ensured that I escaped the { for relevance I believe. Here is the code that I am running:
//Create powershell file
delete __createfile
createfile until ENDOFFILE
#Start a Transcript of all Output
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\BigFix\AdminAccounts\output.txt -append
#Import the LocalAccounts module
#Import-Module -name C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.LocalAccounts\1.0.0.0\Microsoft.PowerShell.LocalAccounts.psd1 -verbose
#Begin removal of Admins other than SSE
$users = Get-WmiObject win32_groupuser | Where-Object {{ $_.GroupComponent -match ‘administrators’ } | ForEach-Object {{[wmi]$_.PartComponent }
$IgnoreList = "ADMIN"
#Write-host $users.name
:OuterLoop
foreach ($user in $users) {{
foreach ($account in $IgnoreList) {{
if ($user.name -like "$account") {{
continue OuterLoop
}
}
Remove-LocalUser -Name $user.Name
}
Stop-Transcript
ENDOFFILE
//move the created file
copy __createfile c:\BigFix\AdminAccounts\removeAdmins.ps1
delete __createfile
//Call script to delete the accounts
waithidden powershell.exe -executionpolicy unrestricted -file "c:\BigFix\AdminAccounts\removeAdmins.ps1"
Above I have the Import Module commented out as I get similar errors when trying it that way.
Here is the transcript that is generated when bigfix runs this task.
**********************
Windows PowerShell transcript start
Start time: 20170502145656
Username: REDACTED\SYSTEM
RunAs User: REDACTED\SYSTEM
Machine: QA-REDACTED (Microsoft Windows NT 6.1.7601 Service Pack 1)
Host Application: powershell.exe -executionpolicy unrestricted -file c:\BigFix\AdminAccounts\removeAdmins.ps1
Process ID: 5552
PSVersion: 5.1.14409.1005
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14409.1005
BuildVersion: 10.0.14409.1005
CLRVersion: 4.0.30319.34209
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\BigFix\AdminAccounts\output.txt
Remove-LocalUser : The term 'Remove-LocalUser' 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:\BigFix\AdminAccounts\removeAdmins.ps1:25 char:5
+ Remove-LocalUser -Name $user.Name
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Remove-LocalUser:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Remove-LocalUser : The term 'Remove-LocalUser' 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:\BigFix\AdminAccounts\removeAdmins.ps1:25 char:5
+ Remove-LocalUser -Name $user.Name
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Remove-LocalUser:String) [], Co
mmandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
**********************
Windows PowerShell transcript end
End time: 20170502145656
**********************
Any thoughts would be greatly appreciated.
If anyone wants be to try any changes I can and will post up the logs. Need to get this figured out ASAP.
To reiterate again, this powershell file runs just fine if I remote into the machine and execute it directly. I know the create file is also working fine as I can simply execute the created file from big fix in CMD using the same cmd I did in wait hidden - powershell.exe -executionpolicy unrestricted -file “c:\BigFix\AdminAccounts\removeAdmins.ps1”
Thanks