Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A...
-
date post
21-Dec-2015 -
Category
Documents
-
view
223 -
download
2
Transcript of Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A...
![Page 1: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/1.jpg)
Powershell, .Net, Com, Wmi etc
Basic
![Page 2: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/2.jpg)
Significant areas of support
Access to .Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features ….and more
![Page 3: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/3.jpg)
What is “Dot” Net
It is the framework Microsoft designed to provide a consistent approach to application development and deployment. The .net framework is built on a set of foundational libraries. It is the basis of what is known as “the stack.”
![Page 4: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/4.jpg)
.Net
Microsoft’s software framework that is now usually installed on most of its operating systems.
![Page 5: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/5.jpg)
![Page 6: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/6.jpg)
CLR:Common Language Runtime
![Page 7: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/7.jpg)
Assemblies
Compiled form of classes Includes executables (files that end in
“.exe”) or Dynamic Link Libraries (files that end in “.dll”)
Actually contains one or more files with a manifest. An assembly is a logical grouping of modules.
Full name (not file name) or Meta Data: Module name Version number (allows multiple modules of the
same name) Public key token
![Page 8: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/8.jpg)
Usefulness of meta data
![Page 9: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/9.jpg)
Powershell
Assemblies already loaded Using additional .Net framework Loading your own assemblies
![Page 10: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/10.jpg)
Directly using .Net Resources
Pre-loaded assemblies [AppDomain]::CurrentDomain.GetAssemblies()
[AppDomain]::CurrentDomain.GetAssemblies() | `ForEach-Object `
{ if ($_.GlobalAssemblyCache){ $_.Location.ToString().Split("\")[4]}}
SystemSystem.DrawingSystem.XmlSystem.ConfigurationSystem.Management.Automation
Microsoft.PowerShell.Commands.UtilityMicrosoft.PowerShell.ConsoleHostMicrosoft.PowerShell.Commands.ManagementMicrosoft.PowerShell.SecuritySystem.Web.Services
![Page 11: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/11.jpg)
Examples using Static Members
[System.Console]::Clear()[System.Math]::Log10(100)$p = `
[System.Diagnostics.Process]::Start("notepad.exe");
$p | Get-Member[System.Int32]::Parse("254");
![Page 12: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/12.jpg)
Testing your own DLL
#You must use the fully qualified path name[Reflection.Assembly]::LoadFile("C:/PSClass/LoanSupport.dll");[Bailey.LoanSupport.LoanSupport]::currentPrimeRate();$k = new-object Bailey.LoanSupport.LoanSupport("Pat", [decimal]120000, 10)$k.Payments()
![Page 13: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/13.jpg)
Creating an Instance$client = New-Object System.Net.WebClient$url = "http://www.cs.calvin.edu/personnel/list"$data = $client.downloadstring($url)$data.Split("`n") | `
ForEach-Object { if ($_ -match ".*@calvin\.edu" ) {($_ -replace ".*mailto:", "") -replace "`".*","" } }
![Page 14: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/14.jpg)
WMI Support
Get-WmiObject -listget-WmiObject win32_computersystem
![Page 15: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/15.jpg)
XML
[xml] Support of XML elements to work through
document Start with the following command:
$vXml = [xml](Get-Content bookorder.xml)
![Page 16: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/16.jpg)
Access Com Objects
COM : Common Object Model Microsoft’s technology to support
interoperation between software regardless of original language
Examples include MS Word, Excel While .Net is slowly replacing COM,
COM is supported by Powershell
http://www.computerperformance.co.uk/powershell/powershell_com.htm
![Page 17: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/17.jpg)
Pulling text out MS Word
$tObj = New-Object -ComObject word.application#$tObj | Get-Member#after exploring let's play#$tObj.Visible = $true$tObj.Version$file = (dir C:\PSClass\small.docx).FullName$doc = $tObj.Documents.Open($file)$text = $doc.Content.TextWrite-Host "Word document had: `n" $text$tObj.Quit()
![Page 18: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/18.jpg)
SQL Server Support
The application sqlps.exe is provided with SQL Server 2008
It can be installed on a client and support SQL Server 2005
Check to see if it is supporting 2.0, if not you can add its functionality to your 2.0 environment.
![Page 19: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/19.jpg)
Adding SQL Server Support
Go to this page: http://www.microsoft.com/downloads/details.aspx?FamilyID=228de03f-3b5a-428a-923f-58a033d316e1&DisplayLang=en
Download and install in the following order:SQLSysClrTypes.msiSharedManagementObjects.msiPowerShellTools.msi
In C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist you will find SQLPS.exe. You will also find the files the DLL's for the provider.
Enter the following commands to install the providers (cmdlet and PSDrive) and then add them C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil.exe Microsoft.SqlServer.Management.PSSnapins.dll C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil.exe Microsoft.SqlServer.Management.PSProvider.dllAdd-PSSnapin SqlServerProviderSnapinget-pssnapin -reg #look for the names of the providers here. Then use the Add-PSSnapin as belowAdd-PSSnapin SqlServerCmdletSnapin100Add-PSSnapin SqlServerProviderSnapin100
![Page 20: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/20.jpg)
Job control in Version 2.0
Start-job : places a job in the background which is not interactive with the console
Get-job : gets information about a job.
Receive-job : Displays all the output that would have gone to the console.
![Page 21: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/21.jpg)
fan-in / fan-out
![Page 22: Basic. Access to.Net Assemblies Support for COM objects Support for WMI objects XML A Powershell console for SQL Server Powershell 2.0 Features.](https://reader035.fdocuments.us/reader035/viewer/2022062421/56649d5a5503460f94a3a452/html5/thumbnails/22.jpg)
Tutorial at
http://powershell.com/cs/blogs/tobias/archive/2009/01/17/xml-part-1-playing-with-rss-feeds-and-xml-content.aspx