title: Powershell create access policy Azure
body: <p>I'm trying to create an access policy so that I can create meetings using Microsoft Graph API on the user's behalf. To do this I need to do a script that is similar to this:</p>
  <pre><code>Connect-MicrosoftTeams
  New-CsApplicationAccessPolicy -Identity Random -AppIds &quot;applicationid&quot; -Description &quot;Users&quot;
  Grant-CsApplicationAccessPolicy -PolicyName Random -Identity &quot;userId&quot;
  </code></pre>
  <p>But when I try to run the second line I get this error:</p>
  <pre><code>At C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\2.3.1\net472\SfBORemotePowershellModule.psm1:63 char:22
  +     $remoteSession = &amp; (Get-CsOnlineSessionCommand)
  +                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [Get-CsOnlineSession], UnauthorizedAccessException
      + FullyQualifiedErrorId : UnauthorizedAccessException,Microsoft.Teams.ConfigApi.Cmdlets.GetCsOnlineSession
   
  Invoke-Command : Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is
   not null or empty, and then try the command again.
  At C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\2.3.1\net472\SfBORemotePowershellModule.psm1:22959 char:38
  + ...    -Session (Get-PSImplicitRemotingSession -CommandName 'New-CsApplic ...
  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidData: (:) [Invoke-Command], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
  </code></pre>
  <p>I'm guessing it has something to do with the first command that it's not remembering my login, but I can't find anywhere on how to do this. Does anyone know what I'm doing wrong and what the correct way is?.</p>
  <p>Edit:
  I finished the first problem. I needed to create an account on the active directory itself because Microsoft accounts weren't allowed. But my second error is still here:</p>
  <pre><code>Invoke-Command : Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is
   not null or empty, and then try the command again.
  At C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\2.3.1\net472\SfBORemotePowershellModule.psm1:22959 char:38
  + ...    -Session (Get-PSImplicitRemotingSession -CommandName 'New-CsApplic ...
  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidData: (:) [Invoke-Command], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
  </code></pre>
  <p>Is there a way to set the session via a parameter or is this something you need to do outside this method?</p>