Search code examples
azurepowershellpowershell-cmdlet

Ho can i run a powershell comand from a .ps1 file?


I have the following:

$command = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$arguments = @('Set-AzLogicApp -ResourceGroupName "MyResourceGroup" -Name "MyLogicAppName" -State "Disabled" -Force')
& $command $arguments

when I run this from command it says Set-AzLogicApp : The term 'Set-AzLogicApp' is not recognized as the name of a cmdlet

Any reason why this is ?


Solution

  • I want to understand why are you calling Powershell.exe from .ps1 file. Anyway all the installed module will be available for execution if you are executing PS file. You can just simply import the module and run the command.

    Additionally , you have to import Az.LogicApp as Joy mentioned after installing it in the machine.

    Code would look like below:

    Import-Module -Name "Az.LogicApp"
    $command = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
    $arguments = @('Set-AzLogicApp -ResourceGroupName "MyResourceGroup" -Name "MyLogicAppName" -State "Disabled" -Force')
    & $command $arguments
    

    enter image description here

    I have tried at my end and it worked for me. Please try and let me know if you need any further assistance.