Posts

Showing posts from 2015
Comparing two files using powershell Hola todos,... as it said in the heading, this is about comparing two files using powershell, I will get down to business and explain few things : - normally two compare two files with powershell, there are two ways (which I know..) that we can use to do this, we can normally use the "Compare-object" CMDLET which was introduced by microsoft, this one can read the contents of both files and show you the difference in case there are some differences. if there are no differences it will show you nothing as a result (No prompts, messages or whatever..). - The other way which i used to do before i knew the "Compare-object" CMDLET is to get the "length" property of each file and just make a condition saying of both lengths are equal, show some message, else show another message. I will introduce both ways here : #The code start here # first code, using compare-object : $source = "D:\we\f1.

Create VM's in Hyper-V using Powershell

Create VM's in Hyper-V using Powershell Hola todos, Today I am gonna talk about a small thing i did in my LAB at home, I got a new windows 2012 server DC installed, created a small Virtual infrastructure using Hyper-V Because i don't like manual work and I believe in the term " Work smart and party hard" I created a small script which will create all my VM's, VHD's and configure them all in a small code. the code is stright forward, I mentioned few comments for those who wants to read them, take a look at the code : #The code start here, #Normally Hyper-V module is already imported in your PS session everytime #you run your PS and Hyper-V server or Hyper-V Managment tools is installed #Reading a text file which contains the server names $R = Get-Content -Path "F:\VMServers.txt" foreach ($rr in $R){ #Creating folders for each Vm # you can create a case or if dstatment here to make sure that this folder #doesn't exixts
Using PowerShell to prevent desktop lockouts... Hola Everyone, Today i wont talk too much because I am kinda loaded, As you see from the heading I wrote these two scratches which will prevent's your desktop from getting lockout. Normally a PC in a domain will be forced to obey some rules, the rules that comes from group policy. One of these famous rules are the lock out time of desktops when the desktop is idle and not used. This can be a problem sometimes specially if the PC is running some process which will be affected some how in case the PC got locked. As rory gallagher used to say on some of his gig's, LETS GET TO WORK!!! : This code Send keys(TAB key) to make the system feel that it's not idle : # Code start here while ($true){ # wait for 40 seconds every time before it hit the key Start-Sleep -seconds 40 [System.Windows.Forms.SendKeys]::SendWait("{%}") | out-null }  # Code end here And this one w
Using  Selenium WebDriver with PowerShell Hola todos... que pasa? This time I am going to show an example on how to use Selenium WebDriver with PowerShell to open the browser and do stuff like checking a checkbox or maybe writing some text in a text box. This one took me sometime to deal with it, it was not a straightforward thing, I spent so much time in front of my laptop, I lost the feeling on my ass for some time after finishing the code, anyway, To find more information about Selenium and how it works, you can dig this link :   http://www.seleniumhq.org/ this WebDriver was built for C#, and of course it can be used and called withing PowerShell or Vb.net easily... Anyway, let’s talk about the code : #Code Start Here : # moving to the folder where Selenium DLL files are… # You can also use Add-Type Cmdlet with -path option, it will do the same. cd "d:\NonOfficialPSModules\selenium-dotnet-2.46.0\net40" [System.Reflection.Assemb

IP Calculator in PowerShell...with IP exclusion

Hola todos... que pasa? It has been a while since i post i was really busy with so many stuff, bottom line, i had this strange requirement at work where i had to create a script to calculate the IP address from a subnet, now normally this means we have to create a bunch of scopes or subnets in the DHCP server, which was my case, i had to create more than 4 thousand scopes on Linux DHCP server. now I was thinking how in the hell I am going to insert all these scopes in the configuration file, of course the first things I came up with was to provide the mandatory information (First IP, last IP, broadcast IP and number of hosts) which was not a big problem, I found this link : https://gallery.technet.microsoft.com/scriptcenter/ipcalc-PowerShell-Script-01b7bd23 This guy did a very good job and save my ass, but this was not the issue, in my situation, I had to exclude the first 48 IP addresses from each scope. Now in Linux DHCP configuration file, each scope was represent