Posts

Create a CRUD Restful Service API using Flask + Mysql [in 7 minutes!]

Image
In this article, we will learn how to build Simple Restful API with flask and Mysql that have capabilities to create, read, update, and delete data from the database.

Flask being a microframework provides the flexibility of the data source for applications and also provides library support for interacting with different kinds of data sources. There are libraries to connect to SQL- and NoSQL-based databases in Flask.


Creating a Flask Application with SQLAlchemy Flask-SQLAlchemy is an extension for flask which adds support for SQLAlchemy to the application. SQLAlchemy is a Python toolkit and Object Relational Mapper that provides access to the SQL database using Python. SQLAlchemy comes with enterprise-level persistence patterns and efficient and high performing database access. 
Flask-SQLAlchemy provides support for the following SQL-based database engines given the appropriate DBAPI driver is installed:
PostgreSQLMySQLOracleSQLiteMicrosoft SQL ServerFirebird Sybase We’ll be using MySQL as …

Error and Exception Handling using Try/catch in powershell

Image
One of the most important components for creating PowerShell scripts is error and exception handling.
I've personally made mistakes while writing scripts without proper exceptions and trying to figure out why it got terminated.😵 
Error and exception handling is often a forgotten component of scripting because it's common to feel that the code should always execute linearly and in an implicit fashion.




This is due to the common practice of taking the small scripts and using them as starting points for more complex scripts. 
The more complex you build your scripts, the higher the probability of failure 🠝 and unexpected results.


In this post, you will learn the following: Types of errorDifferent ways to handle ExceptionsError and exception handling with parametersDifferent ActionsError and exception handling with Try/Catch

PowerShell has two different types of errors which are terminating and non-terminating.

Terminating errors will stop the script from executing further com…

Working with XML Files in Powershell [Parsing]

Image
In the last post, we worked with CSV types of files. The next type of file we're going to look at is Extensible markup language(XML). They are used for various reasons, for example, storing properties data that can be used for configuration and data storage.





XML is one of the basic file extensions and consists of opening and closing tags..


<config> <pctype> <type name="Desktop PC" value="D"></type> <type name="Notebook" value="N"></type> <type name="Tablet PC" value="T"></type> </pctype> <logdir>E:Logs</logdir> <logfile>SCCMLogs.txt</logfile> </config>
Parameters can be added both in a nested fashion and inline. By using the nested approach, you will also have a visual recognition of which objects are on the same level through indentation:


We will start with an example of storing and loading configuration…

Managing CSV Files using Import/Export-CSV in Powershell

Image
In the PowerShell series, we are looking into working with files in PowerShell. The first types of files we are covering which are used are CSV(comma separated values) file types. We are going to look into two important cmdlets import-csv/export-csv which are widely used while working with CSV.






We start with the CSV file extension, as this is the most basic one. We will make use of the previous example, where we stored the currently running processes to file:

#Defining file for export $exportedFile = 'C:\temp\exportedProcesses.csv' #Exporting as CSV - basic Get-Process | Export-Csv $exportedFile #Opening the file psedit $exportedFile
By default, Export-Csv will write a comma-delimited file using ASCII encoding and will completely overwrite any file using the same name.

Export-Csv may be used to add lines to an existing file using the Append parameter. When the Append parameter is used, the input object must have each of the fields listed in the CSV header or an error will …

How to work with PowerShell Files Read/Write using Set-Content & Get-Content

Image
In the PowerShell script writing series, we are working on some of the helpful areas to write powershell scripts. In this series we would continue covering some of the important topics on working with PowerShell read files, write files,folder,subfolders.
Another area where you should become very confident is working with files (read & write), as you will need to work with them very frequently.

First, we will take a look at the basics of working with files by retrieving and writing files and the content of the files. This can be achieved with the Get-Content and Set-Content/Out-File cmdlets.

First of all, we will take a dedicated look at how you can export content to a file:
#Storing working location $exportedProcessesPath = 'C:\temp\test.txt' #Write processes table to file and show the result in Terminal with the -PassThru flag Get-Process | Set-Content -Path $exportedProcessesPath #Open file to verify psedit $exportedProcessesPath #retrieving processes and exporting the…

How to write basic scripts and functions in powershell 6

Image
We are going well with the PowerShell tutorial, we saw how to use credentials and how to work with variables, array, and hash tables.
In the last post, we discussed with the overview of working with script blocks.
In this post, we are going to dig deeper into those with understanding how to design and convert it into functions.
In this post we are going to cover the below topics:

Script vs functionsPass parameters to a scriptConvert to functionsBest practices for designing functions



You can accomplish many tasks in PowerShell by typing a command and pressing Enter in the shell console.        We expect when you are starting up writing commands on the PowerShell console and getting the required output.
      But you hand off a task to someone else and need to make sure that it’s done exactly as planned.
      That’s where scripts come in—and it’s also where functions come in.

SCRIPT OR FUNCTION?

Suppose you have some task, perhaps one requiring a handful of commands in order to complete.
 A scri…