Get-AzureWebsite : Requested value 'Dynamic' was not found - powershell

We have a set of custom powershell modules which use the Azure powershell cmdlets - they have been working fine for over a year. I just set up a new machine and whenever I try to run Get_AzureWebsite I receive the following error:
PS C:\WINDOWS\system32> Get-AzureWebsite 'anything'
Get-AzureWebsite : Requested value 'Dynamic' was not found.
This may just be a machine setup but am worried that these comdlets may be being deprecated - appreciate if anyone can help or knows how to fix this?

It may be fixed by updating the version of Azure PowerShell . More detail please refer to the issue and feedback. Please refer to how to install and configure Azure PowerShell. I didn't reproduce it on the Azure PowerShell v2.1.0. It works successfully.Please try to use the following code to get the current Azure PowerShell version .
(Get-Module -ListAvailable | Where-Object{ $_.Name -eq 'Azure' }) `
| Select Version, Name, Author, PowerShellVersion | Format-List;

Okay so this is versions of Azure and AzureRM cmdlets.
Working install is
Install-Module -Name AzureRM -RequiredVersion 1.3.2
Install-Module Azure -AllowClobber
Not sure about -AllowClobber but this was printed in the Azure Console....
PackageManagement\Install-Package : A command with name 'Get-AzureStorageContainerAcl' is already available on this
system. This module 'Azure' may override the existing commands. If you still want to install this module 'Azure', use
-AllowClobber parameter.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1661 char:21
Guess there is a class in the Storage namespace or something

I installed the latest azure powershell and then ran again the script.
It worked fine.
Just to add you need to restart your machine after installing latest powershell, else you might face error "the required module Azure.Storage is not loaded"

Related

How to fix Nuget Provider "Find-Module" Installation error with PowerShell 7.3?

I've been trying to run a PowerShell script, and upon doing so, I receive a message that NuGet Provider is required.
NuGet provider is required to continue
This version of PowerShellGet requires minimum version '2.8.5.201' of NuGet provider to publish an item to NuGet-based
repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\timothy.granata\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider
by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):
If I input Y, an error is returned:
Find-Module: NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
If I try running Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force as it recommends, I also get an error:
Install-PackageProvider: Unable to find repository with SourceLocation ''. Use Get-PSRepository to see all available repositories.
And finally, if I run Get-PSRepository, that also errors:
Get-PackageSource: Unable to find module providers (PowerShellGet).
In the script I am trying to debug, the code that seems to trigger this prompt is Install-AWSToolsModule SecurityToken -Force. The surrounding code looks like:
if (-not (Get-Module AWS.Tools.Installer -ListAvailable)) {
Install-Module AWS.Tools.Installer -Force
}
Install-AWSToolsModule SecurityToken -Force
Get-AWSCredential -ListProfileDetail | ForEach-Object {
Remove-AWSCredentialProfile -ProfileName $_.ProfileName -Force
}
I have tried:
Reinstalling PowerShell 7
Making sure I am using TLS 1.2 by running [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Running PowerShell as Administrator
Deleting the Modules folder found in my C:\Users<user>\Documents\WindowsPowerShell folder
I'm unsure what else I can try at this point. How can I install the NuGet provider for use with PowerShell 7.3?
Try
$sourceArgs = #{
Name = 'nuget.org'
Location = 'https://api.nuget.org/v3/index.json'
ProviderName = 'NuGet'
}
Register-PackageSource #sourceArgs
Get-PackageProvider | where name -eq 'nuget' | Install-PackageProvider
EDIT
Perhaps try
Invoke-WebRequest 'https://www.powershellgallery.com/api/v2/package/PackageManagement/1.4.8.1' -OutFile $env:temp\nuget.zip
And confirm you're able to download the nuget package. If so, then try
Expand-Archive $env:temp\nuget.zip -DestinationPath 'C:\Program Files\PowerShell\7\Modules\PackageManagement' -Force
Import-Module PackageManagement -Verbose -Force
It seems something with OneDrive was indeed throwing this off as I wondered in my one comment. I found this post which stated (from some Microsoft Documentation):
The user-specific CurrentUser location on Windows is the PowerShell\Modules folder located in the Documents location in your user profile ... Microsoft OneDrive can also change the location of your Documents folder.
I ran $env:PSModulePath and sure enough their was a OneDrive location. I ended up doing what the answer on that post suggested, and excluded the PowerShell directory from OneDrive. After doing this, my script seems to work now (it doesn't produce errors, or that prompt). Ever after doing this, the OneDrive location still shows up from the $env:PSModulePath command, but I guess it falls back to the next modules location if it can't find a directory.

Cast issue on app id when running New-CsApplicationAccessPolicy

I've run into an error after following this document (https://learn.microsoft.com/en-us/graph/cloud-communication-online-meeting-application-access-policy) when trying to set up an application access policy in powershell. This is the cmdlet that was run, which produced the error,
New-CsApplicationAccessPolicy -Identity "MeetingsPolicy" -AppIds "<app-id>" -Description "MeetingsPolicy"
The error received in powershell is the following,
"New-CsApplicationAccessPolicy : Unable to cast object of type 'System.Management.Automation.PSListModifier' to type
'System.String'."
Can anyone help shed any light on what is the problem here and how to fix it please?
P.S Im using Powershell 5.1 on Win 10 and running Powershell in admin mode.
Have also tried the following using "splatting", which also did not work.
$props = #{
identity = 'MeetingsPolicy'
appids = '<app-id>'
description = 'MeetingsPolicy'
}
New-CsApplicationAccessPolicy #props
So it turned out the Microsoft Teams cmdlet module version 3.1.0 has issues in there when installed with no previous version. I had to install the 2.3.2-preview version first, which allowed the cmdlets to work. I then updated this version to 3.1.0 and it works fine.
So the steps you need to take are the following,
i) Remove the teams module from powershell,
Uninstall-Module MicrosoftTeams -Allversions
ii) Install the older version first,
Install-Module -Name MicrosoftTeams -RequiredVersion 2.3.2-preview -AllowPrerelease
iii) Connect to teams
Connect-MicrosoftTeams
v) Update to the latest version (Optional)
Update-Module -Name MicrosoftTeams
Run cmdlet and it should work now.
Credit to Marcus Rath for his post here https://blog.matrixpost.net/teams-powershell-several-cmdlet-doesnt-work-errounable-to-cast-object-of-type-system-management-automation-pslistmodifier-to-type-system-string/, which explains the issue in more detail.

PowerShellGet "unable to find package source" upon Install-Module, despite Find-Module working correctly

I recently created an Azure Artifacts feed for one of the projects in my organization. I followed the instructions at this link.
Most things work. In particular, I'm able to:
Create the feed
Use nuget to push a package to said feed
Register the feed with PowerShell via Register-PSRepository
Run Find-Module -Repository <Repository Name>
The last bit -- running Find-Module -- generates the expected output, viz., a single module with the expected version, name, and description. However, I get the following message when I attempt Install-Module:
PS C:\Windows\System32> install-module -name ADHelpers -Repository 'ADHelpersTest2'
Install-Package: C:\Users\my_name\OneDrive\Documents\PowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:9711
Line |
9711 | … talledPackages = PackageManagement\Install-Package #PSBoundParameters
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unable to resolve package source
| 'https://pkgs.dev.azure.com/my_organization/my_project/_packaging/my_feed/nuget/v2'.
I've scrubbed my organization, project, and feed name, as I don't think that's important for solving this problem.
My question is simple: What could cause this? I'm confused that I'm able to Find-Module just fine, but unable to run Install-Module for the result that Find-Module successfully fetches.
I've been unsuccessful in finding guidance elsewhere, and am unsure what I'm doing wrong.
Thanks in advance -- I appreciate your time.
If you want to install the custom package in the Azure DevOps pipeline, you could add task power shell and run the script Install-Package ADHelpers -Scope CurrentUser -Force
to install the package.
In my sample, the package name is Get-Hello and the result is:
You could refer to this blog and my previous answers for more details

Connect-AzureAD not working with Powershell core

I am trying to run a powershell command - ConnectAzureAD and getting the below error-
'Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.7.16602, Culture=neutral,. Could not find or load a specific file.'
This was working earlier with Powershell 5 but not with powershell core.The versions that i am using are as:
Powershell - 7.0.1
Az.Accounts - 1.8.1 (i have tried updating this but no luck)
AzureAd - 2.0.2.104
Is there any workaroudn for this ? We tried Azure.Standard.Preview from 'Post test Gallery' but it failed the keyVault powershell commands. Any help on this?
Install-Module -Name AzureADPreview -RequiredVersion 2.0.2.89
Import-Module AzureADPreview -Version 2.0.2.89 -UseWindowsPowerShell
As Shiva said, this is a known limitation on .NET CORE that new version assembly cannot be loaded if old version is already loaded. PowerShell is considering module isolation but so far there is no good solution yet.
You can upgrade Microsoft.IdentityModel.Clients.ActiveDirectory to the latest version.
For more details, you could refer to this issue.
You could instead try to use the az rest invoking the graph api.
Until the time az-cli is in par with the AzureAD powershell module you can instead use the graph api
az login --tenant <tenantname.onmicrosoft.com>
$uri = "https://graph.microsoft.com/v1.0/applications"
$allApplications = az rest `
--method GET `
--uri $uri `
--headers 'Content-Type=application/json' | convertfrom-json
$allApplications.value |% {"{0}-{1}" -f $_.appid, $_.displayname}
I have put some samples using az rest here,
https://github.com/joepaulk/utilities/blob/master/manage-azuread-applicationregistrations.ps1
You may also refer to: https://damienbod.com/2020/06/22/using-azure-cli-to-create-azure-app-registrations/ from where i picked up inspiration
Other reference, how az rest use the accesstokens from az cli can be found here,
https://mikhail.io/2019/07/how-azure-cli-manages-access-tokens/

AzureRmRoleAssignment Access denied to the specified API version

I'm getting an error running New-AzureRmRoleAssignment. I want to give an AD group access to a resource group. The script actually works-- the group gets contributor access to the resource group. It just says that it's failing with the message "Access denied to the specified API version".
My script (params not included) is here:
# Import the Task.Common dll that has all the cmdlets we need for Build
import-module Microsoft.TeamFoundation.DistributedTask.Task.Common
import-module Microsoft.TeamFoundation.DistributedTask.Task.Internal
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Internal"
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Azure"
Write-Output "Connecting to Azure"
Initialize-AzurePowershellSupport -ConnectedServiceName $ConnectedServiceName -ErrorAction SilentlyContinue
$subscription = (Get-AzureRmContext).Subscription.SubscriptionName #(Get-AzureRmContext).Subscription.SubscriptionName
New-AzureRmRoleAssignment -ObjectId $objID -RoleDefinitionName $roleName -ResourceGroupName $environment-$featureName
How can I fix the error? The script does what it's supposed to, but the build "fails".
According to the error log, do you login Azure by using service principal. If yes, it is a know issue. Please check the issue on GitHub. The issue is solved on the latest version Azure Power Shell(4.1.0 or later).
You could use the following cmdlet to check your Azure PowerShell version.
Get-Module -ListAvailable -Name Azure -Refresh
The latest version is 4.3.1, you could download it from the link.
If you build the script on VSTS, please use Hosted 2017 build agent, it uses the latest version PowerShell. Please refer to this answer.