Download PowerShell-master/tools/WindowsCI.psm1 from MegaBites-AI/Windows-powershell: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/datasets/MegaBites-AI/Windows-powershell/resolve/main/PowerShell-master/tools/WindowsCI.psm1
- Command line
-
hf download hf://datasets/MegaBites-AI/Windows-powershell/PowerShell-master/tools/WindowsCI.psm1
-
curl -L -o WindowsCI.psm1 https://huggingface.co/datasets/MegaBites-AI/Windows-powershell/resolve/main/PowerShell-master/tools/WindowsCI.psm1
1.81 kB
| # Copyright (c) Microsoft Corporation. | |
| # Licensed under the MIT License. | |
| function New-LocalUser | |
| { | |
| <# | |
| .SYNOPSIS | |
| Creates a local user with the specified username and password | |
| .DESCRIPTION | |
| .EXAMPLE | |
| .PARAMETER | |
| username Username of the user which will be created | |
| .PARAMETER | |
| password Password of the user which will be created | |
| .OUTPUTS | |
| .NOTES | |
| #> | |
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingUsernameAndPasswordParams', '')] | |
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')] | |
| param( | |
| [Parameter(Mandatory=$true)] | |
| [string] $username, | |
| [Parameter(Mandatory=$true)] | |
| [string] $password | |
| ) | |
| $LocalComputer = [ADSI] "WinNT://$env:computername"; | |
| $user = $LocalComputer.Create('user', $username); | |
| $user.SetPassword($password) | Out-Null; | |
| $user.SetInfo() | Out-Null; | |
| } | |
| <# | |
| Converts SID to NT Account Name | |
| #> | |
| function ConvertTo-NtAccount | |
| { | |
| param( | |
| [Parameter(Mandatory=$true)] | |
| [string] $sid | |
| ) | |
| (New-Object System.Security.Principal.SecurityIdentifier($sid)).translate([System.Security.Principal.NTAccount]).Value | |
| } | |
| <# | |
| Add a user to a local security group | |
| Requires Windows PowerShell | |
| #> | |
| function Add-UserToGroup | |
| { | |
| param( | |
| [Parameter(Mandatory=$true)] | |
| [string] $username, | |
| [Parameter(Mandatory=$true, ParameterSetName = "SID")] | |
| [string] $groupSid, | |
| [Parameter(Mandatory=$true, ParameterSetName = "Name")] | |
| [string] $group | |
| ) | |
| $userAD = [ADSI] "WinNT://$env:computername/${username},user" | |
| if($PSCmdlet.ParameterSetName -eq "SID") | |
| { | |
| $ntAccount=ConvertTo-NtAccount $groupSid | |
| $group =$ntAccount.Split("\\")[1] | |
| } | |
| $groupAD = [ADSI] "WinNT://$env:computername/${group},group" | |
| $groupAD.Add($userAD.AdsPath); | |
| } | |