To make this comparison we need to first consider the problem that both approaches help us to solve. When programming any system you are essentially dealing with data and the code that changes that data. These two fundamental aspects of programming are handled quite differently in procedural systems compared with object oriented systems, and these differences require different strategies in how we think about writing code.
Source: Procedural vs Object Oriented Programming
As I have been learning Powershell I have seen numerous sources state over and again that Powershell is a highly “object oriented” language. Not having any background in programming I have been really curious what was meant by this. The above article explains it nicely. It starts out discussing ColdFusion specifically but the bulk of the article is primarily explaining the general concept of Procedural vs. Object Oriented programming (as the title states) and reading through it has helped me understand why powershell works the way it does. Having a basic grasp on this concept should help me out immensely and I would recommend it as a short read for anyone else delving into Powershell, particularly if you are like me and don’t have a strong programming background.
I have been using powershell to automate Internet Explorer interactions with a web application with a login page in our internal environment at work. I ran into an issue with my script because the page I was trying to access was secured with SSL and we were using a self-signed certificate. This causes Internet Explorer to redirect to a warning page rather than going straight to the site. I needed a way to bypass this warning page in code and I finally came up with a solution I am sharing here.
Normally I dive into articles like this with an assumption that people know everything I am talking about. This will be a bit different because on this topic I feel pretty green myself. As this is a fresh subject for me, I am going to treat it as a fresh subject for you. That being said, we are actually going to be working with a somewhat complex script by the time we are done and if you pickup most of the concepts along the way you are going to be off at a sprint with Powershell scripting.
This is redacted version of a powershell script I had to come up with recently to fix an issue with a web application in our environment.
$hostsPath = "$env:windir\System32\drivers\etc\hosts"
$ip = ipconfig | findstr /i IPv4 |Out-string
$ip = $ip.TrimStart("IPv4 Address. . . . . . . . . . . : ")
$ip = $ip.TrimEnd("`n")
$ip = $ip.TrimEnd("`r")
Add-Content $hostsPath "$ip siteurl.com"
I will walk through what is going on here…
We recently had a security requirement come down the line that required me to leave the wading pool of GPO administration behind and dive into the stormy waters of Powershell scripting. I am not going to dive into a full explanation of how to get started on powershell. What I am going to do is present my specific use-case as I ended up having to piece together a script from several different sources… Here we go…
I had some trouble finding some good examples of syntax and full explanation for creating VHD files (attaching new hard drives) from the Azure Powershell command line and attaching them to existing VMs. Here is my quick and dirty method of doing just that…