English 中文(简体)
微软图表生成用户时的编码问题
原标题:Encoding problem when generating user in Microsoft Graph

哪一种特性使得一个PPOST机构到/v1.0/user?

我对以微软图号为名的具有突出特征的生成用户有问题。

我使用以下机构:

{
    "accountEnabled":false,
    "displayName":"ADM Joost Müller",
    "userprincipalname":"[email protected]",
    "mailNickname":"admjmuller",
    "passwordProfile":{      
        "forceChangePasswordNextSignIn":true,
        "forceChangePasswordNextSignInWithMfa":true,
        "password":"Randompasswordgenerated"
    }
}

在我向上面有色人种的人打电话给/v1.0/用户时,我收到了以下反对意见:

@odata.context    : https://graph.microsoft.com/v1.0/$metadata#users/$entity
id                : xxxxxxxx-xxxx-xxxx-xxxx-a72a188e6d9a
businessPhones    : {}
displayName       : ADM Joost M�ller
givenName         : 
jobTitle          : 
mail              : 
mobilePhone       : 
officeLocation    : 
preferredLanguage : 
surname           : 
userPrincipalName : [email protected]

Note the � in the displayname. This is NOT a display problem in Powershell, the Entra ID blade in the Azure portal also shows this character. I ve already tried to forcibly convert the JSON to UTF-8:

$enc = [System.Text.Encoding]::UTF8
$jsonutf8 = $enc.getstring($enc.getbytes($json))

但这并没有解决问题。

我尝试了各种搜索术语,但找不到任何东西可以找到解决办法。 这可能是微不足道的,但如果是,使用错误搜索术语的Im。

实际代码:

function Encode {
  Param(
    [string]$text
  )
  $enc = [System.Text.Encoding]::Utf8
  return $enc.getstring($enc.getbytes($text))
}

function Invoke-GraphPost {
  [cmdletbinding()]
  Param(
    [parameter(Mandatory = $true)][string]$API,
    [parameter(Mandatory = $true)][string]$AccessToken,
    [parameter(Mandatory = $true)]$body,
    [parameter(Mandatory = $false)][string]$Apiversion = "v1.0"
  )
  $header = @{
    Authorization  = ("Bearer {0}" -f $AccessToken)
     Content-Type  =  application/json; charset=utf-8 
  }
  $bodyjson = Encode(ConvertTo-Json -InputObject $body -Compress)
  $URI = Encode(("https://graph.microsoft.com/{0}/{1}" -f $Apiversion, $API))
  try {
    $result = Invoke-RestMethod -Uri $URI -Method Post -Body $bodyjson -Headers $header
  }
  catch {
    $FailMessage = ("Unable to create graph POST request {0} with body {1}" -f $URI, $bodyjson)
    $module.failjson($FailMessage)
  }
  return $result
}

      $password = [System.Web.Security.Membership]::GeneratePassword(12, 4)
      $upnbase = New-EntraUserName -NameFormat "$adminprefix$format" -Voornaam $User.Roepnaam -Infix $User.Voorv_gebnaam -Achternaam $User.Geboortenaam -Domainname $admindomain
      $body = @{
        accountEnabled    = $false
        displayName       = ("ADM {0} {1}" -f $User.Roepnaam.Trim(), $User.Volledige_achternaam.Trim())
        mailNickname      = $upnbase
        userprincipalname = ("{0}@{1}" -f $upnbase, $admindomain)
        passwordProfile   = @{
          forceChangePasswordNextSignIn        = $true
          forceChangePasswordNextSignInWithMfa = $true
          password                             = $password
        }
      }
$newuser = Invoke-GraphPost -API users -AccessToken $token.access_token -body $body

New-EntraUserName 产生一个基于特定名称、固定名称和姓氏的独特用户名称(对于Joost Müller而言,准确代码与问题无关),生成的用户名是同mjmuller,因此没有中心。

Joost

最佳回答

www.un.org/french/ga/president


<>Solutions

  • <>strong>PowerShell 7.4+:

    • Given the above, your code should work as-is - except that you don t need the redundant Encode call.
  • www.un.org/Depts/DGACM/index_spanish.htm 权力 iii

    • 备选案文1:

      • Omit the (pointless) Encode call.
      • Don t add a Content-Type entry to $header.
      • Instead, add a -ContentType application/json; charset=utf-8 argument to the Invoke-RestMethod call.
    • 备选案文2:

      • <Perform the UTF-8 encoding your Self and pass a byte protocol/em> to<>>:><>-Body> para amount:

         Invoke-RestMethod -Uri $URI -Method Post -Headers $header -Body (
           [Text.UTF8Encoding]::new().GetBytes(
             (ConvertTo-Json -InputObject $body -Compress)
           )
         )
        
问题回答

暂无回答




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...