我正在寻找一些关于组合组合以下脚本的PowerShell脚本的指导:
Connect-AzureAD
Revoke-AzureADUserAllRefreshToken -ObjectId johndoe@contoso.com
Get-AzureADUserRegisteredDevice -ObjectId johndoe@contoso.com | Set-AzureADDevice -AccountEnabled $false
我希望实现的是将所有三个cmdlet合并到我的工作人员可以运行的单个脚本中,它将提示我们希望运行脚本的用户名。假设我需要在这个脚本中的某个地方添加$ObjectID = Read-Host -Prompt
。
事先感谢您对如何做到这一点的任何建议或指导。
发布于 2022-06-24 21:07:47
假设我理解你的问题,而你只是想要一种方法,把所有这些按照正确的顺序组合在一起,就在这里。
# Use one or the other depending on if you want to use the username or objectID
$Username = Read-Host -Prompt
#$ObjectId = Read-Host -Prompt
Connect-AzureAD
# Use one or the other depending on if you want to use the username or objectID
$User = Get-AzureADUser -SearchString $Username
#$User = Get-AzureADUser -ObjectId $ObjectId
if ($null -ne $User) {
Revoke-AzureADUserAllRefreshToken -ObjectId $User.ObjectId
Get-AzureADUserRegisteredDevice -ObjectId $User.ObjectId | Set-AzureADDevice -AccountEnabled $false
} else {
Write-Warning "No user found with the specified criteria"
}
https://stackoverflow.com/questions/72749246
复制相似问题