Share via


PowerShell을 사용하여 App-V 데이터베이스를 설치하고 연결된 보안 식별자를 변환하는 방법

업데이트 날짜: 2015년 9월

적용 대상: Application Virtualization 5.1

다음 PowerShell 절차에 따라 임의 개수의 AD DS(Active Directory 도메인 서비스) 사용자 또는 컴퓨터 계정을, SQL 스크립트를 실행할 때 Microsoft SQL Server에서 사용하는 표준 형식 및 16진수 형식 모두의 SID(보안 식별자)로 변환할 수 있습니다.

이 절차를 시도하기 전에 다음 목록에 나와 있는 정보와 예제를 읽고 이해해야 합니다.

  • .INPUTS - SID 형식으로 변환하는 데 사용되는 계정입니다. 단일 계정 이름 또는 계정 이름의 배열이 될 수 있습니다.

  • .OUTPUTS - 표준 및 16진수 형식의 해당 SID를 포함하는 계정 이름의 목록입니다.

  • -

    .\ConvertToSID.ps1 DOMAIN\user_account1 DOMAIN\machine_account1$ DOMAIN\user_account2 | Format-List.

    $accountsArray = @("DOMAIN\user_account1", "DOMAIN\machine_account1$", "DOMAIN_user_account2")

    .\ConvertToSID.ps1 $accountsArray | Write-Output -FilePath .\SIDs.txt -Width 200

    #>

AD DS(Active Directory 도메인 서비스) 사용자 또는 컴퓨터 계정을 형식 지정된 SID(보안 식별자)로 변환하려면

  1. 다음 스크립트를 텍스트 편집기로 복사하고 PowerShell 스크립트 파일(예: ConvertToSIDs.ps1)로 저장합니다.

    <#
    .SYNOPSIS
    This PowerShell script will take an array of account names and try to convert each of them to the corresponding SID in standard and hexadecimal formats.
    .DESCRIPTION
    This is a PowerShell script that converts any number of Active Directory (AD) user or machine accounts into formatted Security Identifiers (SIDs) both in the standard format and in the hexadecimal format used by SQL server when running SQL scripts.
    .INPUTS
    The account(s) to convert to SID format. This can be a single account name or an array of account names. Please see examples below.
    .OUTPUTS
    A list of account names with the corresponding SID in standard and hexadecimal formats
    .EXAMPLE
    .\ConvertToSID.ps1 DOMAIN\user_account1 DOMAIN\machine_account1$ DOMAIN\user_account2 | Format-List
    .EXAMPLE
    $accountsArray = @("DOMAIN\user_account1", "DOMAIN\machine_account1$", "DOMAIN_user_account2")
    .\ConvertToSID.ps1 $accountsArray | Write-Output -FilePath .\SIDs.txt -Width 200
    #>
    
    function ConvertSIDToHexFormat
    {
       param([System.Security.Principal.SecurityIdentifier]$sidToConvert)
    
       $sb = New-Object System.Text.StringBuilder
        [int] $binLength = $sidToConvert.BinaryLength
        [Byte[]] $byteArray = New-Object Byte[] $binLength
       $sidToConvert.GetBinaryForm($byteArray, 0)
       foreach($byte in $byteArray)
       {
       $sb.Append($byte.ToString("X2")) |Out-Null
       }
       return $sb.ToString()
    }
     [string[]]$myArgs = $args
    if(($myArgs.Length -lt 1) -or ($myArgs[0].CompareTo("/?") -eq 0))
    {
     [string]::Format("{0}====== Description ======{0}{0}" +
    "  Converts any number of user or machine account names to string and hexadecimal SIDs.{0}" +
                   "  Pass the account(s) as space separated command line parameters. (For example 'ConvertToSID.exe DOMAIN\\Account1 DOMAIN\\Account2 ...'){0}" +
                   "  The output is written to the console in the format 'Account name    SID as string   SID as hexadecimal'{0}" +
                   "  And can be written out to a file using standard PowerShell redirection{0}" +
                   "  Please specify user accounts in the format 'DOMAIN\username'{0}" + 
                   "  Please specify machine accounts in the format 'DOMAIN\machinename$'{0}" +
                   "  For more help content, please run 'Get-Help ConvertToSID.ps1'{0}" + 
                   "{0}====== Arguments ======{0}" +
                   "{0}  /?    Show this help message", [Environment]::NewLine) 
    {
    else
    {  
        #If an array was passed in, try to split it
        if($myArgs.Length -eq 1)
        {
            $myArgs = $myArgs.Split(' ')
        }
        #Parse the arguments for account names
        foreach($accountName in $myArgs)
        {    
            [string[]] $splitString = $accountName.Split('\')  # We're looking for the format "DOMAIN\Account" so anything that does not match, we reject
            if($splitString.Length -ne 2)
            {
                $message = [string]::Format("{0} is not a valid account name. Expected format 'Domain\username' for user accounts or 'DOMAIN\machinename$' for machine accounts.", $accountName)
                Write-Error -Message $message
                continue
            }
    
            #Convert any account names to SIDs
            try
            {
                [System.Security.Principal.NTAccount] $account = New-Object System.Security.Principal.NTAccount($splitString[0], $splitString[1])
                [System.Security.Principal.SecurityIdentifier] $SID = [System.Security.Principal.SecurityIdentifier]($account.Translate([System.Security.Principal.SecurityIdentifier]))
            }
            catch [System.Security.Principal.IdentityNotMappedException]
            {
                $message = [string]::Format("Failed to translate account object '{0}' to a SID. Please verify that this is a valid user or machine account.", $account.ToString())
                Write-Error -Message $message
                continue
            }
            #Convert regular SID to binary format used by SQL
            $hexSIDString = ConvertSIDToHexFormat $SID
            $SIDs = New-Object PSObject
            $SIDs | Add-Member NoteProperty Account $accountName
            $SIDs | Add-Member NoteProperty SID $SID.ToString()
            $SIDs | Add-Member NoteProperty Hexadecimal $hexSIDString
            Write-Output $SIDs
        }
    }
    
  2. PowerShell 콘솔을 열려면 시작을 클릭하고 PowerShell을 입력합니다. Windows PowerShell을 마우스 오른쪽 단추로 클릭하고 관리자 권한으로 실행을 선택합니다.

  3. 이 절차의 1단계에서 저장한 스크립트를 실행하고 계정을 전달하여 인수로 변환합니다.

    예:

    .\ConvertToSID.ps1 DOMAIN\user_account1 DOMAIN\machine_account1$ DOMAIN\user_account2 | Format-List” 또는 “$accountsArray = @("DOMAIN\user_account1", "DOMAIN\machine_account1$", "DOMAIN_user_account2")

    .\ConvertToSID.ps1 $accountsArray | Write-Output -FilePath .\SIDs.txt -Width 200”

    App-V에 대한 제안 사항이 있으신가요? 여기에서 제안 사항을 추가하거나 투표해 보세요.
    App-V 문제가 있으신가요?App-V TechNet 포럼을 사용하세요.

참고 항목

기타 리소스

PowerShell을 사용하여 App-V 5.1 관리

-----
TechNet 라이브러리에서 MDOP에 대해 자세히 알아보거나 TechNet 위키에서 문제 해결을 검색하거나 Facebook 또는 Twitter에서 Microsoft를 팔로우할 수 있습니다.
-----