1 / 22

Powershell , .Net , Com, Wmi etc

Basic. Powershell , .Net , Com, Wmi etc. 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. What is “Dot” Net.

arden
Download Presentation

Powershell , .Net , Com, Wmi etc

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic Powershell, .Net, Com, Wmi etc

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

  3. 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.”

  4. .Net Microsoft’s software framework that is now usually installed on most of its operating systems.

  5. CLR:Common Language Runtime

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

  7. Usefulness of meta data

  8. Powershell • Assemblies already loaded • Using additional .Net framework • Loading your own assemblies

  9. Directly using .Net Resources • Pre-loaded assemblies [AppDomain]::CurrentDomain.GetAssemblies() [AppDomain]::CurrentDomain.GetAssemblies() | ` ForEach-Object ` { if ($_.GlobalAssemblyCache){ $_.Location.ToString().Split("\")[4]}} System System.Drawing System.Xml System.Configuration System.Management.Automation Microsoft.PowerShell.Commands.Utility Microsoft.PowerShell.ConsoleHost Microsoft.PowerShell.Commands.Management Microsoft.PowerShell.Security System.Web.Services

  10. 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");

  11. 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()

  12. 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 "`".*","" } }

  13. WMI Support Get-WmiObject-list get-WmiObject win32_computersystem

  14. XML • [xml] • Support of XML elements to work through document • Start with the following command: $vXml= [xml](Get-Content bookorder.xml)

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

  16. Pulling text out MS Word $tObj = New-Object -ComObjectword.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.Text Write-Host "Word document had: `n" $text $tObj.Quit()

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

  18. 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-PSSnapinSqlServerProviderSnapinget-pssnapin -reg  #look for the names of the providers here.  Then use the Add-PSSnapin as belowAdd-PSSnapin SqlServerCmdletSnapin100Add-PSSnapin SqlServerProviderSnapin100

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

  20. fan-in / fan-out

  21. Tutorial at • http://powershell.com/cs/blogs/tobias/archive/2009/01/17/xml-part-1-playing-with-rss-feeds-and-xml-content.aspx

More Related