So I am trying to run some powershell script on my WPF app to update my IpRules on Azure but even simple script like "Write-Output 'Hello, World!'" gives me this error: Could not load file or assembly 'System.Management.Automation, Version=7.2.8.0, Culture=neutral, PublicKeyToken=token123456'. The system cannot find the file specified. Here is my code:
public Collection<PSObject> GetExistingFirewallIPRules(string script, Dictionary<string, object> scriptParameters)
{
PowerShell ps = PowerShell.Create();
ps.AddScript(script);
return ps.Invoke();
}
And here is .csproj
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.ResourceManager.AppService" Version="1.0.0" />
<PackageReference Include="Azure.ResourceManager.CosmosDB" Version="1.2.0" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.3.1" />
<PackageReference Include="Prism.Core" Version="8.1.97" />
<PackageReference Include="Prism.Wpf" Version="8.1.97" />
<PackageReference Include="System.Management.Automation" Version="7.2.8" />
</ItemGroup>
How can I fix this error or is it any other way to update my CosmosDB IpRules in Azure portal than running powershell (eg. "Update-AzCosmosDBAccount -ResourceGroupName $resourceGroupName -Name $accountName -IpRangeFilter $ipFilter") script?