전자 메일 주소뿐만 아니라 도메인에서 새 사용자를 만들려는 PowerShell 스크립트가 있습니다. 이 스크립트는 Exchange에서 직접 실행할 때 작동합니다. 로컬 컴퓨터에서 같은 명령이 작업을 수행하는 것이 실행PowerShell 스크립트가 로컬에서 실행되지만 원격에서 오류가 발생했습니다.
The term 'Get-ADUser' is not recognized as the name of a cmdlet...
: 나는 내 로컬 PC에서 그것을 수행하려고 할 경우, 하나 Enter-PSSession
또는 Invoke-Command
와 나는 오류가 발생합니다. 원격 컴퓨터에서이 명령을 실행하면 원격으로 스크립트를 실행하지 않아도됩니다.
$cred = Get-Credential
$first_name = Read-Host -Prompt "What is the new user's first name?"
$last_name = Read-Host -Prompt "What is the new user's last name?"
$copy_from = Read-Host -Prompt "Copy from other user (leave blank if not)?"
$password = Read-Host -Prompt "New user's password?"
$ss_password = ConvertTo-SecureString -String $password -AsPlainText -Force
$new_user_name = $last_name.Substring(0,3) + $first_name.Substring(0,2)
$new_user_name = $new_user_name.ToLower()
Write-Host "Creating user $new_user_name..." -ForegroundColor Green
if ([string]::IsNullOrEmpty($copy_from))
{
Write-Host "Setting up new user (not copying...)" -ForegroundColor Yellow
New-ADUser -Name "$first_name $last_name" -AccountPassword $ss_password -SamAccountName $new_user_name -PassThru | Enable-ADAccount
}
else
{
$copy_from_user = Get-ADUser -Identity $copy_from
Write-Host "Copying user from: " $copy_from_user.Name -ForegroundColor Yellow
$ou = $copy_from_user.DistinguishedName -replace '^cn=.+?(?<!\\),'
New-ADUser -Name "$first_name $last_name" -AccountPassword $ss_password -Path $ou -SamAccountName $new_user_name -PassThru | Enable-ADAccount
$new_user = Get-ADUser -Identity $new_user_name
#Time to copy their group memberships
Get-ADUser -Identity $copy_from -Properties memberof | Select-Object -ExpandProperty memberof | Add-ADGroupMember -Members $new_user_name
}
$pn = $new_user_name + "@INDY"
Set-ADUser -Identity $new_user_name -GivenName $first_name -Surname $last_name -UserPrincipalName $pn
#Now create email
$email_select = Read-Host -Prompt "Select email domain (1. Woodmizer; 2. Lastec; 3. Brightstone)"
if ($email_select -eq 2)
{
$domain = "@lastec.com"
}
elseif ($email_select -eq 3)
{
$domain = "@brightstoneabrasives.com"
}
else
{
$domain = "@woodmizer.com"
}
$email_address1 = $first_name.Substring(0,1) + $last_name + $domain
Write-Host "Creating mailbox $email_address1..." -ForegroundColor Green
Enable-Mailbox -Identity $new_user_name -Database "Mailbox Database 1188513962"
Start-Sleep -s 10
Get-Mailbox -Identity $new_user_name | Set-Mailbox -EmailAddresses @{add="$email_address1"} -EMailAddressPolicyEnabled $false
Get-Mailbox -Identity $new_user_name | Set-Mailbox -PrimarySmtpAddress $email_address1 -EmailAddressPolicyEnabled $false
Write-Host "Finished." -ForegroundColor Green
AD cmdlet을 사용하기 전에 Import-Module ActiveDirectory를 사용할 수 있습니까? –
나는 그것을 시도했다고 믿고, 모듈이없는 것처럼 오류가 발생했다. 내일 정확한 말을 제공 할 수 있습니다. – bendparker