The blog post mainly emphasizes PowerShell. This is because I work with PowerShell myself. You can also use this for other scripts. I myself also have a repository for php.
Repository and change control in Visual Studio the basics.
When I first started with PowerShell I had a folder in OneDrive where I kept a few scripts starting with ‘Login-Office365’. It were pre-scripted scripts for me I could use as a servicedesk engineer. After awhile the scripts in this folder became more and more. I created folders to categorize them.
This worked perfectly until I found Azure Automation, that was magical. I didn’t need to browse through folders and search for my scripts. I used Azure Automation as a ‘database’.
After awhile I had 200+ scripts in Azure Automation and the search function didn’t do much good anymore.
I had files like this:
Imagine so many scripts for almost the same function for 80% of the cmdlets in Office 365, Exchange Online, Active Directory, and others.
It became a complete mess. I had to confess to my colleague that it wasn’t working for me anymore. He told and explained me all about Visual Studio Online Repository and I made a tutorial out of it.
Because I think more people should know about this I made a tutorial. I hope you’ll use it and otherwise comment below if you even have a better idea.
PowerShell to Visual Studio Online Repository, the requirements.
There are a few requirements though. They’re simple and you might be using them already.
- Download and install Visual Studio Code
- Download and install Visual Studio
- Create an account for Visual Studio Online or use your live account.
Let’s bring PowerShell to a Visual Studio Online Repository.
- Go to Visualstudio Online
- Login to your account > open your profile and start a New Team Project.
As you can see in the image I already have a Projects. Below the project is a button to create a New Team Project.
Fill in a Project name and leave the rest like it is.
(Yes, I know I called mine PHP! Why would I need 2 PowerShell Libraries? ;-))
After you create the new project we can clone it to Visual Studio. There is a button to clone it to Visual Studio. Make sure you’ve installed Visual Studio by now!
Your browser will ask you if you want to open the file format with Visual Studio. That’s up to you to decide, but you cannot clone your repository if you don’t.
Click Open Microsoft Visual…ndler Selector
Visual Studio will start and you’ll see your repository to the right.
Before you click Clone lets look at the locations.
- Is the location in Visual Studio Online. We cannot change that.
- Is the location on your local disk. I changed the location for myself to a OneDrive directory to keep an extra backup. This is up to you.
Click Clone when you’re ready.
You’ll see this message:
The repository was cloned successfully. Create a new project or solution in this repository.
So our clone was successful, great!
We got a repository in Visual Studio Online which is synced locally. What does that mean?
Now we’ve got a repository we can start using the change control Visual Studio offers and keep an online ‘database’ for all our scripts/files/whatever we use on a daily basis.
Now we’ve got a repository in Visual Studio Online we can start using all the features VSO has to offer and keep an online ‘database’ for all our scripts, files, or whatever you want to use it for. I use it on a daily basis.
Change control in Visual Studio.
For me personally this is one of the most important parts. You can change control a repository that’s shared with other users.
At this point we’ll start using Visual Studio Code.
- Start visual studio code.
- Go to File > Open Folder > Open local folder where you cloned the repository.
- Now we’ve got the folder open, we can start creating a new file.
Click the New file button next to the folder name.
As you can see for yourself, the file became green with a U, but there is also a 1 at the source control (The button that looks like a sharing button).
If you hover your mouse over it, it will say:
“Source Control (Ctrl + Shift + G) – 1 pending changes”
Let’s go to Source Control.
There is a change for the test.php file.
Lets make another change to the file and add some content.
So first I added “Beast!” and after that I added “BlBAlbLAbLABALBALAB”
It will compare the changes:
Lets say you want to revert the changes, you can right click the file under the folder and click the button Discard Changes.
If the changes are correct you can click the + button. This will Stage the changes. The changes are staged and you’ll be able to commit your changes.
To commit a change you can write down a message of why you commited this change:
Write down your message and press commit:
This will only commit the changes in your local repository though!
Open the 3 dots, find sync, and sync your repository back to Visual Studio Online.
As you can see all of my scripts are synced back to Visual Studio Online:
Get the best out of Visual Studio Code for PowerShelling.
Let’s start with installing the Extensions necessary to use PowerShell comfortably.
Go to extensions:
I’ve got 3 extension installed, but we’re going for two extensions.
- PowerShell – This extension is necessary to develop PowerShell scripts so start downloading it.
- vscode-icons – This one isn’t necessary, but will show an icon before the scripts and will make your life a lot easier.
Let’s take a look at the theme
Visual Studio Code has quite a few themes, but if you’re a true PowerShell guru there is one theme that is meant for you. One of the themes is named “PowerShell_ISE”
You are only able to load the theme if you have the PowerShell extension installed.
Go to preferences > Color Theme > select the PowerShell_ISE Theme.
Another huge perk is the search function. It will not only search for file names, but it will also search in the content. This makes it extremely useful. I can compare scripts quickly and decide which one I want to use.
Here is an example:
last but not least, the graphical user interface
Can’t say much about this one, but I like the GUI so much more than that of PowerShell_ISE, but that is preference of course.
That’s it! As I said above, you can also use it for other scripts.
Do you have better ideas, comments, or positive feedback? Then let me know in the comments below.