Quantcast
Channel: LANDESK User Community : Blog List - All Communities
Viewing all articles
Browse latest Browse all 80

Using PowerShell to Retrieve Machine Information from LDMS

$
0
0

This was originally posted under the PowerShell group, but I wanted to repost it here so that I have everything in one place...

 

I hope to post many more articles here, so I'm going to start this off by launching a series of posts on how to use PowerShell to automate some simple tasks for LANDESK Management Suite (LDMS). Over the course of these posts, I hope to start building a library of PowerShell cmdlets that can be used by anyone using Management Suite. All of these scripts will using the LANDESK Message-Based SDK (MBSDK), or other web services available on the the LDMS core server.

 

This first script is a very simple one that returns basic information about the devices in inventory. But before we can retrieve any information, we have to connect to the MBSDK on the web server. This is accomplished by using a three PowerShell command:

 

$mycreds = Get-Credential

$ldWS = New-WebServiceProxy -uri http://localhost/MBSDKService/MsgSDK.asmx?WSDL-Credential$mycreds

$ldWS.ResolveScopeRights()

 

(Note: In all of the samples, I am running PowerShell on my core server and so will be referencing the core server as "localhost". If you run these commands on your core server, they should work without modification.)

 

The first command will prompt you for your user name and password so that they can then be passed to the second command. The second command creates a proxy to the MBSDK web service. The third command completes the authentication to the web service and resolves what rights you have to the core server; according to the MBSDK documentation, the call to the function is required.

 

Now that we have a connection to the core server, we can issue additional commands to the core server. In this post, I am only going to issue a simple command to retrieve the information about the computers managed by this core server. The command is:

 

$ldWS.ListMachines("")

 

This command returns a single object that has two properties: a count and a list of devices. The output from the command on my system looked like this:

 

                                                      count Devices

                                                      ----- -------

                                                       1101 {LDMS01-PC01, LDMS01-PC02, LDMS01-PC03...}

 

We can then look at one of the individual devices by specifying the first device in the list:

 

$ldWS.ListMachines("").Devices[0]

 

Since this command returns a single object, PowerShell presents it in a list format instead of a table format.

 

GUID       : {001A9C58-02D4-F345-9780-ED21AED997AB}

DeviceName : LDMS01-PC01

DomainName : ldms01.com

LastLogin  : LDMS001

IPAddress  : 010.127.041.052

SubNetMask : 255.255.255.000

MACAddress : A01D48F561C6

OSName     : Microsoft Windows 7 Enterprise Edition, 64-bit

 

To see all of the devices in the list in a table format, we simply specify the list of devices and pass that through the pipeline to the Format-Table cmdlet.

 

$ldWS.ListMachines("").Devices | Format-Table *

 

On my system, this resulted in output that looked something like this:

 

GUID           DeviceName     DomainName    LastLogin    IPAddress      SubNetMask     MACAddress     OSName

----           ----------     ----------    ---------    ---------      ----------     ----------     ------

{001A9C58-0... LDMS01-PC01    lmds01.com    LDMS001      010.127.041... 255.255.255... A01D48F561C6   Microsoft...

{00A6C526-1... LDMS01-PC02    lmds01.com    LDMS002      010.015.002... 255.255.240... 8C705AD39BA4   Microsoft...

{00BD1FD8-7... LDMS01-PC03    lmds01.com    LDMS003      010.127.041... 255.255.255... D4C9EFE84C7D   Microsoft...

{010DB8C1-3... LDMS01-PC04    lmds01.com    LDMS004      010.232.052... 255.255.255... F0921CEA4580   Microsoft...

<and so and and so forth>

 

To make the output more presentable, you can use the following formating commands instead of just the base Format-Table cmdlet.

 

$machineTable = @{Expression={$_.DeviceName};Label="Device Name";width=14}, `

                @{Expression={$_.DomainName};Label="Domain Name";width=15}, `

                @{Expression={$_.IPAddress};Label="IP Address";width=18}, `

                @{Expression={$_.MACAddress};Label="MAC Address";width=15}, `

                @{Expression={$_.OSName};Label="OS Name";width=90}

$ldWS.ListMachines("").Devices | Format-Table $machineTable

 

This changes the output into something more useful and more readable.

 

Device Name    Domain Name     IP Address         MAC Address     OS Name

-----------    -----------     ----------         -----------     -------

LDMS01-PC01    ldms01.com      010.127.041.052    A01D48F561C6    Microsoft Windows 7 Enterprise Edition, 64-bit

LDMS01-PC02    ldms01.com      010.015.002.069    8C705AD39BA4    Microsoft Windows 7 Enterprise Edition, 64-bit

LDMS01-PC03    ldms01.com      010.127.041.067    D4C9EFE84C7D    Microsoft Windows 7 Enterprise Edition, 64-bit

LDMS01-PC04    ldms01.com      010.232.052.150    F0921CEA4580    Microsoft Windows 7 Enterprise Edition, 64-bit

<and so and and so forth>

 

I hope you found this information useful and I would love to hear what you have to say. If you leave comments, I will do my best to reply.


Viewing all articles
Browse latest Browse all 80


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>