Share via


Cómo instalar las bases de datos de App-V y convertir los identificadores de seguridad asociados (SID) con PowerShell

Se aplica a: Application Virtualization 5.1

Utilice el procedimiento de PowerShell siguiente para convertir cualquier número de cuentas de usuario o de máquina de Servicios de dominio de Active Directory (AD DS) en identificadores de seguridad (SID) con formato, ambos con el formato estándar y el formato hexadecimal que se usa en Microsoft SQL Server al ejecutar scripts SQL.

Antes de intentar este procedimiento, debería leer y comprender la información y los ejemplos que se muestran en la lista siguiente:

  • .INPUTS: cuenta o cuentas usadas para convertir al formato SID. Puede ser un nombre de cuenta único o una serie de nombres de cuenta.

  • .OUTPUTS: lista de nombres de cuenta con el SID correspondiente en formatos estándar y hexadecimal.

  • Ejemplos:

    .\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

    #>

Para convertir cualquier número de cuentas de usuario o de máquina de Servicios de dominio de Active Directory (AD DS) en identificadores de seguridad (SID) con formato

  1. Copie el siguiente script en un editor de texto y guárdelo como archivo de script de PowerShell, por ejemplo 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. Para abrir una consola de PowerShell, haga clic en Inicio y escriba PowerShell. Haga clic con el botón secundario en Windows PowerShell y seleccione Ejecutar como administrador.

  3. Ejecute el script que ha guardado en el primer paso de este procedimiento pasando las cuentas que se deben convertir como argumentos.

    Por ejemplo,

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

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

    ¿Tiene alguna sugerencia sobre App-V? Agregue o vote sugerencias aquí.
    ¿Tiene un problema de App-V? Use el foro de TechNet de App-V.

Véase también

Otros recursos

Administración de App-V 5.1 con PowerShell

-----
Puede obtener más información sobre MDOP en la Biblioteca de TechNet, mediante la búsqueda de información de solución de problemas en la sección TechNet Wiki, o a través de Facebook o Twitter.
-----