Recent Comments

Category: Windows PowerShell

Windows PowerShell discussion with System Administrators and Developers: Feedback – ISE has no good Add-On’s. Many uses ISE Steroids which is an excellent add-on for PowerShell ISE. We do have script browser and analyzer now.

Comparing ISE with Visual Studio is not fair 🙂 Why do you want to do that? WMF 5.0 and it’s features are far better than earlier versions. So, indeed PowerShell ISE is also grown up 🙂

We don’t have commands to meet all our needs in Windows PowerShell so we create a function , Proxy Functions, Workflow, Class or modules for various needs. Similarly, we can create our own add on for ISE. Let us see a quick demo of it using Visual Studio 2013.

We can easily create this using with the available VSIX if not you can opt for WPF Control Library and create a add-on as required by adding Microsoft.PowerShell.GPowerShell. In this article we will make our job easy by using VSIX – Click to download .

Read the documentation and install the VSIX as required. Now, we will create a simple CustomAddon which will insert a code or some string into the current ISE file.

Open Visual Studio 2013 and choose Visual C# and select PowerShell ISE Add-on for VS2013. Name it as required! In our case I have named it as CustomAddOn as shown below

Now open up the UserControl1.xaml.cs code – Just double click it and the below will be the default code.

Default Code

C#

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using Microsoft.PowerShell.Host.ISE;

namespace CustomAddOn

{

/// <summary>

/// Interaction logic for UserControl1.xaml

/// </summary>

public partial class UserControl1 : IAddOnToolHostObject

{

public UserControl1()

{

InitializeComponent();

}

<strong> public ObjectModelRoot HostObject

{

get

{

throw new NotImplementedException();

}

set

{

throw new NotImplementedException();

}

}</strong>

}

}

Okay, we have the pseudo code – let’s do some modification and test the ISE add-on to insert a code or some string in ISE. To do that first we need to comment the below lines and just add get and set like shown below

Comment Code

C#

1

2

3

4

5

6

7

8

9

10

11

12

13

public ObjectModelRoot HostObject

{

//get

//{

// throw new NotImplementedException();

//}

//set

//{

// throw new NotImplementedException();

//}

get;

set;

}

Now, it’s time for us to add the controls and code as required. For, testing let us add a button and trigger an event which inserts code or string in ISE current file.

Recently I was reading the article Service Desk Plus REST API. Well! yeah not really great for Automation at this point of time but partially served my needs.I love automation so thought of spinning up PowerShell to do few tasks which I perform on daily basis with minimum tool permission. Indeed, service desk plus has reporting feature and can be automated (Personally not interested to deep dive in it). Reporting automation in tool depends on the server hardware / software capacity and tool configuration. Consider Mid level managers and multiple technicians configured reporting for their needs we may fall in performance degradation. Many will do SQL query to pull reports. Do, remember after pulling reports we should work on Excel to make good reports.

What can we do with Service Desk Plus REST API?

Request Operations [We will cover only this part in this blog!]

Notes Related Operations

Work log Related Operations

Change Related Operations

CMDB Related Operations

Technician Related Operations

Let’s start Automating Reporting, to begin with ensure you have below perquisites

Know about your server host name or URL of the tool and the port information – Eg: http://ServerName:<port>

Keep the API documentation handy – we need to refer to this while coding.

Contact your tool admin and get the API key – Do remember if you are a tool admin you can’t generate one for yourself with the same ID.

You can fetch Request Number by querying your SQL DB using PowerShell – Since, we have enough code in the internet we will skip the PowerShell code for retrieving inform from SQL DB.

My first attempt failed because I didn’t read the API documentation 🙂

Ay! it’s doing something! grab the API documentation and follow the instructions. We need to post the operation name and we have got our API key already from tool admin!. Now use the PowerShell code like shown below

To retrieve the status information we need to see the response code like shown below

$data.API.response.operation.result

Okay! let us see the ticket information in PowerShell ISE 🙂 But! how do we know that information and status are in result and detail node? Simple, see the API documentation of Viewing Request – Example is shown in the below image

Cool! We are good to fire the below PowerShell code.

$data.API.response.operation.Details.parameter

TaDa! The sample output is below

Service Desk Plus documentation time format is human readable format and this is not why? Well! I am not from manage engine team so I have no answer but as a System Admin I can read that as EPOCH time format. So, again do little more code in PowerShell and convert this time format.

“Date and Time Format is {0}” -f (([datetime]’1/1/1970′).AddSeconds([int](1439388404268 / 1000)))

Bangalore PowerShell User Group announced a Work Shop event to showcase DSC Basics and Advanced topics. Let’s go declarative ! Stop not! @PSBUG opened a gate. Yeah! Book for the workshop and make use of it. Come and explore! Learn and Share!

Requirement

Query AD [Active Directory] computers and insert into SQL Express.

Considerations

Requirement is just an one liner. We need to consider a lot before we deliver this to production.

Do we need all computers from AD or just enabled? Yeah! We need only enabled computers. If Admin disables / enables a computer or remove / adds a computer in AD the SQL express table should update accordingly.

Do we need only client operating systems? Yeah! We need this is for Client OS reporting.

Summary

To summarize the requirement customer needs a solution which should do the below tasks.