0 votes

Trying to create a custom command to run a powershell script, but I keep getting an error saying it can't find the file or path supplied for launching powershell. Specifically:

 $powershellPath = "$env:windir\system32\windowspowershell\v1.0\powershell.exe"

Line is failing.

This path does exist on my computer, and I can launch powershell from this location using Command Prompt. Am I missing something?

by (100 points)
0

Hello,

Please, provide the full script you are using and a screenshot of the error. You can post the details here or send to us at support@adaxes.com.

0

The full script is as below:

Function Execute-Procedure {
    $Context.CloudServices.ConnectExchangeOnline()   
    $waitTimeMilliseconds = 9 * 60 * 1000


    # Start a new instance of Windows PowerShell and run the script
    $powershellPath = "$env:windir\system32\windowspowershell\v1.0\powershell.exe" #"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
    $process = Start-Process 'X:<filepathreadacted>PowerShellQuery.ps1' -NoNewWindow -ArgumentList ("-Users %username% -AccessRights PublishingEditor -IncludeFolders '\%param-SelectedFolder%' -Recurse -Confirm:$false") -PassThru
    $process.WaitForExit($waitTimeMilliseconds)

    #Run the below in powershell manually to do this manually for now
    #& "X:<filepathreadacted>PowerShellQuery.ps1" -Users %username% -AccessRights PublishingEditor -IncludeFolders "\%param-SelectedFolder%" -Recurse -Confirm:$false
}

# Run this procedure
Execute-Procedure 

The error is as shown

error.png

Line 7 being the powershell launch line:

powershell.png

At first, I thought it was the ps1 file being on a network location but after swapping it to a local location and looking closer at the error, it is the powershell launch line that is the error.

Powershell is indeed in that location however:

powershell location.png

I've restarted Adaxes service and my PC, yet the issue remains. Even launching the custom command with only the launch line and no other commands, it is still the error of can't find file or path. But I can launch it from this location using command prompt.

Please let me know what I have done wrong? Does Adaxes need some Import or other statement to access the powershell .exe?

1 Answer

0 votes
by (288k points)
selected by
Best answer

Hello,

The $powershellPath variable is not used anywhere in the script so you can just remove the corresponding line. At the same time, it is generally not required to force Adaes to start/import PowerShell or anything of the kind. Additionally, we recommend you to just place the full code into the Adaxes action rather than storing it in a file. The main reason is that such scripts are no part of Adaxes functionality and require additional maintenance.

0

OK. The entire script file is very large, but when moving it into adaxes, I get two more errors:

" The term 'Get-Recipient' 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. Stack trace: at GetUserIdentities, <No file>: line 79 ↲ at Execute-Procedure, <No file>: line 207 ↲ at <ScriptBlock>, <No file>: line 281 The term 'Get-PublicFolder' 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. Stack trace: at FindFoldersToUpdate, <No file>: line 44 ↲ at Execute-Procedure, <No file>: line 223 ↲ at <ScriptBlock>, <No file>: line 281 "

I've seen this before, where Adaxes doesn't have the same cmdlets as full powershell, which is why I was trying to run the file itself in Powershell directly.

The affected lines are:

        $id = (Get-Recipient $user).PrimarySmtpAddress
        $foldersFound = @(Get-PublicFolder -Recurse:$recurseOnFolders $includeFolder -ResultSize Unlimited | Sort-Object Identity)

I can attach the entire file if needed, but it is a big one.

What should I do in this case? Is there some Adaxes equivalent to these, or is there some better way to run a Powershell script with cmdlets that Adaxes doesn't recognize?

+1

Hello,

Whenever you run a cdlet and it is not recognized, there can be two possible causes. One is that the corresponding PowerShell module is not installed on the computer where Adaxes service runs. The other is that the Adaxe service account (specified during Adaxes installation) does not have access to the module (for example, due to the module installation peculiarities).

As for Exchange cmdlets, the error occurs because they are executed outside the connection being established. For an example of the proper approach, see https://www.adaxes.com/script-repository/connect-to-exchange-with-powershell-s506.htm.

0

The connection to Exchange line added fixed it, you are absolutely correct!

# Connect to Exchange Online
$Context.CloudServices.ConnectExchangeOnline() 

Thank you so much for the detaild and quick guidence! Everything is working as it should now.

Related questions

0 votes
1 answer

Hi, I'm trying to add a column to a report to retrieve the last login data from AAD/Graph using the script posted here but i'm running into the ... [0].signInActivity.lastSignInDateTime # Assign a column value to $Context.Value $Context.Value = $lastLogonDate

asked Feb 22, 2022 by richarddewis (260 points)
0 votes
1 answer

I have a scheduled task that runs the following PowerShell script. $user = New-AdmUser -Server $domain -AdaxesService localhost -Path $workdayDn -ChangePasswordAtLogon $true -PassThru - ... ) over all objects. I'm stumped! Any help would be super appreciated.

asked Sep 5 by emeisner (100 points)
0 votes
0 answers

As title indicates, searching or browsing a group doesnt show its members. However, when I choose a modify group function, for that same logged in user, the group members ... or explicit filters to viewing members that I can see. What could be causing this?

asked Nov 2, 2021 by manomano (80 points)
0 votes
1 answer

I am trying to use this script from the script repository: https://www.adaxes.com/script-repository/enable-mfa-with-phone-number-for-a-user-in-microsoft-365-s686.htm I ... if I just didn't install it correctly because Adaxes Powershell doesn't recognize it.

asked Oct 10, 2023 by ocanizales (60 points)
0 votes
0 answers

Hello there, We have guest accounts created in AD (on our DMZ DC) that use the first initial + last name format for username with the last 4 digits of their mobile ... there any special way I should be updating a username and UPN from PowerShell? Thanks, Chris

asked Jul 13, 2018 by Bowman4864 (270 points)
3,542 questions
3,233 answers
8,227 comments
547,808 users