Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.05 KB | None | 0 0
  1. #Styles
  2. <#
  3. [Enum]::GetNames([Microsoft.Office.Interop.Word.WdBuiltinStyle]) | ForEach {
  4. [pscustomobject]@{Style=$_}
  5. } | Format-Wide -Property Style -Column 4
  6. #>
  7.  
  8. $User = $env:USERNAME
  9. $CreatedBy = Get-aduser -Filter {SamAccountName -eq $User} -Properties Name | Select Name
  10.  
  11. Function Invoke-SQL ( $DataSource, $Database , $sqlCommand) {
  12. $UserID="<USERID>"
  13. $pwd = "<PASSWORD>"
  14. $connectionString = "Data Source=$dataSource; " + "Initial Catalog=$database; " + "User ID=$userID; " + "Password=$pwd"
  15. $connection = new-object system.data.SqlClient.SQLConnection($connectionString)
  16. $command = new-object system.data.sqlclient.sqlcommand($sqlCommand,$connection)
  17. $connection.Open()
  18.  
  19. $adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command
  20. $dataset = New-Object System.Data.DataSet
  21. $adapter.Fill($dataSet) | Out-Null
  22.  
  23. $connection.Close()
  24. $dataSet.Tables
  25. }
  26.  
  27.  
  28. $Deployments = (Invoke-SQL "<SERVER>" "<DATABASE>" "
  29. Select
  30. Case
  31. When FeatureType = 1 Then 'Application'
  32. When FeatureType = 2 Then 'Package'
  33. End [DeploymentType],
  34. SoftwareName, CollectionName from v_deploymentsummary
  35. Where FeatureType in ('1','2')
  36. Order by SoftwareName
  37. ") | Out-Gridview -OutputMode Single
  38.  
  39.  
  40. $SoftQuery = (Invoke-SQL "<SERVER>" "<DATABASE>" "
  41. Create Table #FNAPP
  42. (
  43. Assign int,
  44. Policy int,
  45. AppCI int,
  46. DTCI int,
  47. DTModelID int,
  48. AppName varchar(200),
  49. Collection varchar(200)
  50. )
  51. Insert Into #FNApp (Assign, Policy, AppCI, DTCI, DTModelID, AppName, Collection)
  52. Select Distinct Assignmentid, PolicyModelID, APPCI, DTCI, DTModelID, AppName, CollectionName from fn_AppDeploymentAssetDetails(1033)
  53.  
  54. ;WITH XMLNAMESPACES (DEFAULT 'http://schemas.microsoft.com/SystemCenterConfigurationManager/2009/AppMgmtDigest')
  55.  
  56. Select
  57. Case
  58. When FeatureType = 1 Then 'Application'
  59. When FeatureType = 2 Then 'Package'
  60. End [Type],
  61. SoftwareName, VDS.CollectionName, VDS.PackageID,
  62.  
  63. Case
  64. When FeatureType = '1' Then CAST(VDS.AssignmentID as varchar)
  65. When FeatureType = '2' Then CAST(OfferID as varchar)
  66. End [DeploymentID],
  67. Case
  68. When FeatureType = 1 Then 'N/A'
  69. When FeatureType = 2 Then VDS.ProgramName
  70. End [ProgramName],
  71. DeploymentTime,
  72. Case
  73. When FeatureType = 1 Then ContentSource
  74. When FeatureType = 2 Then PkgSourcePath
  75. End [SourceFiles],
  76. Case
  77. When FeatureType = 1 Then Right(AppUniqueID, Charindex('/', Reverse(AppUniqueID)) -1)
  78. When FeatureType = 2 Then SourceVersion
  79. End [Version],
  80. Case
  81. When SDMPackageDigest.value('(/AppMgmtDigest/DeploymentType/Installer/InstallAction/Args/Arg/@Name) [1]', 'nvarchar(MAX)') = 'InstallCommandLine' Then SDMPackageDigest.value('(/AppMgmtDigest/DeploymentType/Installer/InstallAction/Args/Arg) [1]', 'nvarchar(MAX)')
  82. When FeatureType = 2 Then CommandLine
  83. End [CommandLine]
  84.  
  85. from v_DeploymentSummary VDS
  86. Left Join v_Package VP on VDS.PackageID = VP.PackageID
  87. Left Join v_content VC on VDS.packageid = VC.PkgID and VC.contentsource is not null
  88. Left Join vAppstatsummary VAS on VAS.DisplayName = VDS.SoftwareName
  89. Left Join v_program VPro on VPRO.packageid = VDS.PackageID and VPro.programname <> '*'
  90. Left Join vCIAllContents VCIA on VCIA.Content_ID = VC.Content_ID
  91. Left Join v_ConfigurationItems VCI on VCI.ci_id = VCIA.ci_id
  92. Where Softwarename = '$($Deployments.SoftwareName)' and CollectionName = '$($Deployments.CollectionName)'
  93.  
  94. Drop Table #FNApp
  95. ")
  96.  
  97. $Source = $($SoftQuery.SourceFiles)
  98. $Files = get-childitem -Path "$($Softquery.sourceFiles)"
  99.  
  100. Foreach ($File in $Files | ? {$_.name -like '*.ps1'}){
  101. If ($Softquery.commandline -match "$($File.name)"){
  102. $ScriptContents = Get-content -Path "$($SoftQuery.sourcefiles)\$($File.name)"
  103. }
  104. }
  105.  
  106. #Add-Type -AssemblyName Microsoft.Office.Interop.Word
  107. $Word = New-Object -ComObject Word.Application
  108. $Word.Visible = $False
  109. $Document = $Word.Documents.Add()
  110. $Selection = $Word.Selection
  111.  
  112. $Selection.Style = 'Title'
  113. $Selection.Font.Bold = 1
  114. $Selection.font.Size = 24
  115. $Selection.TypeText("$($SoftQuery.SoftwareName)")
  116. $Selection.ParagraphFormat.Alignment = 1
  117. $Selection.TypeParagraph()
  118.  
  119. $Selection.Style = 'SubTitle'
  120. $Selection.Font.Bold = 1
  121. $Selection.font.Size = 18
  122. $Selection.TypeText("$($SoftQuery.Type) Deployment")
  123. $Selection.ParagraphFormat.Alignment = 1
  124. $Selection.TypeParagraph()
  125.  
  126. $Selection.Style = 'SubTitle'
  127. $Selection.Font.Bold = 1
  128. $Selection.font.Size = 10
  129. $Selection.TypeText("Document created on: $(get-date)")
  130. $Selection.ParagraphFormat.Alignment = 1
  131. $Selection.TypeParagraph()
  132.  
  133. $Selection.Style = 'SubTitle'
  134. $Selection.Font.Bold = 1
  135. $Selection.font.Size = 10
  136. $Selection.TypeText("Document created by: $($CreatedBy.name)")
  137. $Selection.ParagraphFormat.Alignment = 1
  138. $Selection.TypeParagraph()
  139.  
  140. If ($SoftQuery.programname -ne 'N/A'){
  141. $Selection.Style = 'Normal'
  142. $Selection.Font.Bold = 0
  143. $Selection.font.Size = 12
  144. $Selection.TypeText("Program Name: $($SoftQuery.ProgramName)")
  145. $Selection.ParagraphFormat.Alignment = 0
  146. $Selection.TypeParagraph()
  147. }
  148.  
  149. $Selection.Style = 'Normal'
  150. $Selection.Font.Bold = 0
  151. $Selection.font.Size = 12
  152. $Selection.TypeText("Package ID: $($SoftQuery.PackageID)")
  153. $Selection.ParagraphFormat.Alignment = 0
  154. $Selection.TypeParagraph()
  155.  
  156. $Selection.Style = 'Normal'
  157. $Selection.Font.Bold = 0
  158. $Selection.font.Size = 12
  159. $Selection.TypeText("Version: $($SoftQuery.Version)")
  160. $Selection.ParagraphFormat.Alignment = 0
  161. $Selection.TypeParagraph()
  162.  
  163. $Selection.Style = 'Normal'
  164. $Selection.Font.Bold = 0
  165. $Selection.font.Size = 12
  166. $Selection.TypeText("Deployed to Collection: $($SoftQuery.CollectionName)")
  167. $Selection.ParagraphFormat.Alignment = 0
  168. $Selection.TypeParagraph()
  169.  
  170. $Selection.Style = 'Normal'
  171. $Selection.Font.Bold = 0
  172. $Selection.font.Size = 12
  173. $Selection.TypeText("Deployment ID: $($SoftQuery.DeploymentID)")
  174. $Selection.ParagraphFormat.Alignment = 0
  175. $Selection.TypeParagraph()
  176.  
  177. $Selection.Style = 'Normal'
  178. $Selection.Font.Bold = 0
  179. $Selection.font.Size = 12
  180. $Selection.TypeText("Deployment Start Time: $($SoftQuery.DeploymentTime)")
  181. $Selection.ParagraphFormat.Alignment = 0
  182. $Selection.TypeParagraph()
  183.  
  184. $Selection.Style = 'Normal'
  185. $Selection.Font.Bold = 0
  186. $Selection.font.Size = 12
  187. $Selection.TypeText("Source File Location: $Source")
  188. $Selection.ParagraphFormat.Alignment = 0
  189. $Selection.TypeParagraph()
  190.  
  191. $Selection.Style = 'Normal'
  192. $Selection.Font.Bold = 0
  193. $Selection.font.Size = 12
  194. $Selection.TypeText("Command Line: $($SoftQuery.CommandLine)")
  195. $Selection.ParagraphFormat.Alignment = 0
  196. $Selection.TypeParagraph()
  197.  
  198. If ($ScriptContents){
  199. $Selection.Style = 'Normal'
  200. $Selection.Font.Bold = 0
  201. $Selection.font.Size = 12
  202. $Selection.TypeText("Script Details: ")
  203. $Selection.ParagraphFormat.Alignment = 0
  204. $Selection.TypeParagraph()
  205.  
  206. $Selection.Style = 'Normal'
  207. $Selection.Font.Bold = 0
  208. $Selection.font.Size = 12
  209. $Selection.TypeText("$ScriptContents")
  210. $Selection.ParagraphFormat.Alignment = 1
  211. $Selection.TypeParagraph()
  212. }
  213.  
  214.  
  215. $Report = 'C:\Users\<USER>\Desktop\Application Deployment Documentation.doc'
  216. $Document.SaveAs([ref]$Report,[ref]$SaveFormat::wdFormatDocument)
  217. $word.Quit()
  218. #Remove-variable * -ErrorAction SilentlyContinue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement