How to Export Target Devices into a .CSV File

How to Export Target Devices into a .CSV File

book

Article ID: CTX118754

calendar_today

Updated On:

Description

This article details how to export Target Devices from a Provisioning Services (PVS) database in a formatted Comma Separated Values (CSV) file.

Requirements

SQL Server Management Studio or bcp.exe, both of which are components of a full SQL Server or SQL Server Express install.


Instructions

Complete the following steps to export target devices from a Provisioning Server database using the SQL Server Management Studio:
  1. Connect to the SQL Server hosting the Provisioning Server database.
  2. Right-click on the Provisioning Server database and select Tasks > Export Data.

     User-added image

  3. Ensure that the value in the Database field is correct, and select Next.

    User-added image

  4. Set Destination as Flat File Destination and specify a path and file name (with .csv extension) to export. Ensure Column names in the first data row check box is not selected.

    User-added image

  5. Select Write a query to specify the data to transfer option and click Next.

     User-added image

  6. Specify the following SQL query to export all Devices in a farm, alphabetically by Site, Collection, and Device name:

    SELECT D.deviceName, D.deviceMac, S.siteName, C.collectionName
    FROM dbo.Device D, dbo.Collection C, dbo.Site S
    WHERE D.collectionID = C.collectionID AND C.siteID = S.siteID
    ORDER BY S.siteName, C.collectionName, D.deviceName
  7. Click Next.

    User-added image
  8. Use the default options and click Next Next Finish.

 To export Target Devices from a Provisioning Server database using the Bulk Copy Utility:
  1. Open a Command Prompt on the SQL Server hosting the Provisioning Server database. See Additional Resources section for an MSDN article detailing advanced usage of bcp.exe, including executing the utility from a remote machine.

  2. Specify the following command to export all Devices in a farm, alphabetically by Site, Collection, and Device name:
bcp.exe "SELECT D.deviceName, D.deviceMac, S.siteName, C.collectionName FROM PVSDEMO.dbo.Device D,
PVSDEMO.dbo.Collection C, PVSDEMO.dbo.Site S WHERE D.collectionID = C.collectionID AND C.siteID = 
S.siteID ORDER BY S.siteName, C.collectionName, D.deviceName" queryout "C:\ExportedDevices.csv" -c -t"," –T

where, PVSDEMO is the name of the PVS database on the SQL Server, and C:\ExportedDevices.csv is the path and file name where you want to export.

Issue/Introduction

This article describes how to export Target Devices into a .CSV File.

Additional Information

Citrix eDocs - Importing Target Devices into a Collection

MSDN SQL Server 2005 Tools and Utilities Reference article for BCP: http://msdn.microsoft.com/en-us/library/ms162802(SQL.90).aspx

Additional example queries (if using with BCP, ensure to prefix the tables listed in the FROM clause with the name of the database followed by a period as seen in the example):

  • Export only the Devices that are members of the Collection Desktops:
SELECT D.deviceName, D.deviceMac, S.siteName, C.collectionName  
FROM dbo.Device D, dbo.Collection C, dbo.Site S
WHERE D.collectionID = C.collectionID AND C.siteID = S.siteID AND C.collectionName='Desktops'
ORDER BY S.siteName, C.collectionName, D.deviceName
  • Export Devices from all Sites and Collections within a Farm whose name begins with XD:
SELECT D.deviceName, D.deviceMac, S.siteName, C.collectionName, 
FROM dbo.Device D, dbo.Collection C, dbo.Site S
WHERE D.collectionID = C.collectionID AND C.siteID = S.siteID AND D.deviceName LIKE ‘XD%’
ORDER BY S.siteName, C.collectionName, D.deviceName
  • Export Devices from all Sites and Collections within a Farm that belong to a View named XSP:
SELECT D.deviceName, D.deviceMac, S.siteName, C.collectionName
FROM dbo.Device D, dbo.Collection C, dbo.Site S, dbo.SiteView V, dbo.SiteViewDevice Z
WHERE D.collectionID = C.collectionID AND C.siteID = S.siteID AND S.siteID = V.siteID AND V.siteViewID = Z.siteViewID AND D.deviceID = Z.deviceID AND V.siteViewName=’XSP’
ORDER BY S.siteName, C.collectionName, D.deviceName