自动化无聊的任务

时间:2019-01-25 19:28:41

标签: powershell loops scripting sysadmin

我的脚本的后半部分无法按我希望的方式运行。我相信我使用了不正确的cmdlet。我正在尝试将活动目录中的组添加到便携式计算机/ PC上的本地管理员帐户。然后,将域用户添加到高级用户组。

我想从AD中提取组名,我认为此cmdlet可以这样做。有什么想法吗?

我只跑了下半场但收到错误。我尝试了其他cmdlet,但我认为这是最准确的。

#change computer name of the device + condition 
$answer = Read-Host -Prompt 'Do you want to change the computer name?'



# First condition - 1) name comupter 2) take user creds 3) Rename computer using stored cred 4) write host if yes is the answer
if ($answer -match "yes"){
    $computername = Read-Host -Prompt "What will be the name of the computer?"
    #This part of the script will contain your credentials to change the computername and priveledges
    $cred = Get-Credential -Message "This will be used to changed the computername. Do not worry!"
    #$cred = Read-Host -Prompt "Enter your network username" - Uneeded string
    Rename-Computer -NewName "$computername" -LocalCredential $cred -DomainCredential $cred
    Write-Host "Computername has been changed to $computername successfully!" 
    }


 #Second condition - If answer is no move on to second portion of the script to set privledges
elseif($answer -match "no"){
    Write-Host "Moving to the next part of the script"
    }


#Third condition - If answer is anything else - loop to the beginning of the script to accept the right answer
else{
    write-host "Please answer with yes or no"
    }

#Second half of script        
#Adding AD group to local adminitrator 
$localuser= Read-Host "Enter username of the PowerUser."
Add-LocalGroupMember -Group "Administrator" -Member "memeber"
Add-LocalGroupMember -Group "Power Users" -Member $localuser + "tamu.jaguar.edu"

0 个答案:

没有答案