SHOW:
|
|
- or go back to the newest paste.
| 1 | Function Global:Set-LocalAdminGroupMembership | |
| 2 | {
| |
| 3 | ||
| 4 | ||
| 5 | <# | |
| 6 | .Synopsis | |
| 7 | ||
| 8 | .Description | |
| 9 | ||
| 10 | .Parameter $ComputerName, | |
| 11 | ||
| 12 | .Example | |
| 13 | PS> Set-LocalAdminGroupMembership -ComputerName $ComputerName -Account 'YourAccount' | |
| 14 | //youraccount will usually be set as 'guest' while running this script | |
| 15 | .Link | |
| 16 | about_functions | |
| 17 | about_functions_advanced | |
| 18 | about_functions_advanced_methods | |
| 19 | about_functions_advanced_parameters | |
| 20 | ||
| 21 | #> | |
| 22 | ||
| 23 | ||
| 24 | ||
| 25 | [CmdletBinding()] | |
| 26 | param( | |
| 27 | [Parameter(Position=0, ValueFromPipeline=$true)] | |
| 28 | $ComputerName = '.', | |
| 29 | [Parameter(Position=1, Mandatory=$true)] | |
| 30 | $Account | |
| 31 | ) | |
| 32 | ||
| 33 | ||
| 34 | Process | |
| 35 | {
| |
| 36 | ||
| 37 | if($ComputerName -eq '.'){$ComputerName = (get-WmiObject win32_computersystem).Name}
| |
| 38 | $ComputerName = $ComputerName.ToUpper() | |
| 39 | ||
| 40 | ||
| 41 | $Domain = $env:USERDNSDOMAIN | |
| 42 | ||
| 43 | if($Domain){
| |
| 44 | $adsi = [ADSI]"WinNT://$ComputerName/administrators,group" | |
| 45 | $adsi.add("WinNT://$Domain/$Account,group")
| |
| 46 | }else{
| |
| 47 | Write-Host "Not connected to a domain." -foregroundcolor "red" | |
| 48 | } | |
| 49 | ||
| 50 | ||
| 51 | }# Process | |
| 52 | ||
| 53 | ||
| 54 | }# Set-LocalAdminGroupMembership |