1

I was able to run

Install-Module -Name AzureADPreview

But when I run

$policy = New-AzureADPolicy -Definition @('{"TokenLifetimePolicy" {"Version":1,"AccessTokenLifetime":"02:00:00"}}')

It run into this error

New-AzureADPolicy: The term 'New-AzureADPolicy' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

How do I get this keyword to work in cloud shell?

Kevin
  • 75
  • 6

1 Answers1

1

I tried to reproduce the same in my environment and got the same error as below:

$policy = New-AzureADPolicy -Definition @('{"TokenLifetimePolicy" {"Version":1,"AccessTokenLifetime":"02:00:00"}}') -DisplayName TestPolicy -IsTenantDefault

enter image description here

Please note that, before installing AzureADPreview you need uninstall AzureAD Module like below:

Uninstall-Module AzureAD 
Install-Module AzureADPreview 
Import-Module AzureADPreview 
Get-Module -Name AzureADPreview
connect-AzureAd

enter image description here

I tried to create the policy by using the below command and got the results successfully like below:

$policy = New-AzureADPolicy -Definition @('{"TokenLifetimePolicy":{"Version":1,"AccessTokenLifetime":"02:00:00"}}') -DisplayName "WebPolicyScenario" -IsOrganizationDefault $false -Type "TokenLifetimePolicy"

enter image description here

Reference:

Set lifetimes for tokens - Microsoft Entra | Microsoft Docs

Rukmini
  • 6,015
  • 2
  • 4
  • 14
  • I got was able to get to step `connect-AzureAd` but after that `New-AzureADPolicy` failed with following error```New-AzureADPolicy : Error occurred while executing NewPolicy Code: Authentication_Unauthorized Message: User was not found. InnerError:``` – Kevin Aug 08 '22 at 20:07
  • Please check this [Authenticating with Azure Active Directory on powershell](https://stackoverflow.com/questions/43301218/authenticating-with-azure-active-directory-on-powershell) – Rukmini Aug 09 '22 at 03:49