脚本内容:
param (
# [Parameter(Mandatory=$True)]
[string]$UserName
)
Import-Module ActiveDirectory
#$UserName = $args[0]
$SamAccount = (Get-ADUser -Filter {(Name -eq $UserName) -or (SamAccountName -eq $UserName)}).SamAccountName
$Custom = @{}
$Custom['ExtensionAttribute1'] = 'GoogleGsuite'
Set-ADUser -Identity $SamAccount -Add $Custom
Start-Sleep -s 60
$Gsuite = (Get-ADUser -Identity $SamAccount -Properties *).extensionAttribute1
if($Gsuite -eq 'GoogleGsuite')
{
write-output "$UserName,Google GSuite Enable successfully!"
}
else
{
$GoogleGsuiteValue = Get-ADUser -Identity $User -Properties * | %{$_.extensionAttribute1}
$GsuiteValue = "$GoogleGsuiteValue"
$GsuiteValueDictionary = @{"GoogleGSuite"="Judgment Error";""="Google GSuite Not Enabled" }
$GoogleGsuiteValueReport = $GsuiteValueDictionary[$GsuiteValue]
}
如图示: