{"id":4412,"date":"2012-12-28T00:01:00","date_gmt":"2012-12-28T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/12\/28\/protect-your-powershell-scripts-with-version-control\/"},"modified":"2012-12-28T00:01:00","modified_gmt":"2012-12-28T00:01:00","slug":"protect-your-powershell-scripts-with-version-control","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/protect-your-powershell-scripts-with-version-control\/","title":{"rendered":"Protect Your PowerShell Scripts with Version Control"},"content":{"rendered":"<p><strong>Summary:<\/strong> Guest blogger and Microsoft PFE Stefan Stranger talks about using version control to protect your Windows PowerShell scripts.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today I am pleased to present a guest blog post written by Senior Premier Field Engineer Stefan Stranger. The Scripting Wife and I were privileged to hear Stefan speak at the first-ever <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/11\/26\/the_2d00_first_2d00_ever_2d00_dutch_2d00_powershell_2d00_user_2d00_group.aspx\" target=\"_blank\">Dutch Windows PowerShell user group meeting<\/a>. Following Stefan&rsquo;s presentation, I asked him if he would write up his presentation as a guest blog post. Today is the result of that request.<\/p>\n<p>Take it away, Stefan &#8230;<\/p>\n<h2>Protect your PowerShell scripts with version control<\/h2>\n<p>During the first <a href=\"http:\/\/www.dupsug.com\/\" target=\"_blank\">Dutch PowerShell User Group<\/a> meeting, I gave a presentation about protecting your Windows PowerShell scripts with version control, and this is a blog post about how you can get started implementing version control.<\/p>\n<p>Software developers would not think about working on a project without some form of version control. So why is this so unusual for the IT professional who is responsible for maintaining Windows PowerShell scripts containing hundreds of lines of scripts? Version control or source control are terms used for the practice of tracking changes in the source code. There are several tools that can help you implement version control such as GIT, Mercurial, and Team Foundation Server. This blog post explains how you can protect your Windows PowerShell scripts by using Team Foundation Server (TFS) for version control. After implementing version control you will never have to worry that you did not copy your script after you made some changes in your script and it no longer works.<\/p>\n<h2>What is version control?<\/h2>\n<p>With version control, you can:<\/p>\n<ul>\n<li>Record changes<\/li>\n<li>Review older versions<\/li>\n<li>Undo changes<\/li>\n<\/ul>\n<p>Other names used for version control are:<\/p>\n<ul>\n<li>Revision control<\/li>\n<li>Source control<\/li>\n<\/ul>\n<h2>Version control software<\/h2>\n<p><a href=\"http:\/\/msdn.microsoft.com\/en-us\/vstudio\/ff637362.aspx\" target=\"_blank\">Microsoft Visual Studio Team Foundation Server 2012 (TFS)<\/a> is the collaboration platform at the core of Microsoft&#8217;s application lifecycle management (ALM) solution. TFS supports agile development practices, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/vstudio\/jj158939\" target=\"_blank\">multiple IDEs and platforms<\/a> locally or <a href=\"http:\/\/tfspreview.com\/\" target=\"_blank\">in the cloud<\/a>, and it gives you the tools you need to effectively manage software development projects throughout the IT lifecycle.<\/p>\n<h2>Team foundation components<\/h2>\n<p>Team Foundation Server consists of the following components:<\/p>\n<ul>\n<li>Client tier (like Visual Studio, Office, command line, others)<\/li>\n<li>Application tier (Team Foundation Web Services API)<\/li>\n<li>Data tier (SQL Server)<\/li>\n<\/ul>\n<h2>TFS source control steps<\/h2>\n<p>When you want to start implementing version control, here are some basic commands you need to know:<\/p>\n<ul>\n<li><strong>Add \u2012&nbsp;<\/strong>Adds files and folders from a location in the local file system to a version control server for Team Foundation.<\/li>\n<li><strong>Check out&nbsp;\u2012&nbsp;<\/strong>Makes the local file writable and changes its pending Change status to &#8220;edit&#8221; in the workspace.<\/li>\n<li><strong>Check in&nbsp;\u2012&nbsp;<\/strong>Commits a pending change to a Team Foundation Server repository.<\/li>\n<\/ul>\n<p><strong>Note<\/strong> &nbsp;&nbsp;There are many more commands, but this will get you started with some basic version control activities.<\/p>\n<h2>What do you need to get started with version control?<\/h2>\n<p>Microsoft offers <a href=\"http:\/\/tfs.visualstudio.com\/\" target=\"_blank\">Team Foundation Service<\/a>, which is a cloud-based Team Foundation Service. At the moment, it is free for up to five users, and for a limited time, all use is free! You can also install TFS 2012 locally. For more information, see <a href=\"http:\/\/msdn.microsoft.com\/en-us\/vstudio\/ff637362.aspx\" target=\"_blank\">Team Foundation Server<\/a>. There is also an <a href=\"http:\/\/www.microsoft.com\/visualstudio\/eng\/downloads\" target=\"_blank\">Express version available<\/a> to get started.<\/p>\n<p>In this blog post, we are going to set up the following version control environment on a computer running Windows&nbsp;8:<\/p>\n<ul>\n<li><a href=\"http:\/\/tfs.visualstudio.com\/\" target=\"_blank\">Team Foundation Service<\/a> \u2012 TFS in the cloud.<\/li>\n<li><a href=\"http:\/\/www.microsoft.com\/en-au\/download\/details.aspx?id=30656\" target=\"_blank\">Team Explorer Microsoft Visual Studio 2012<\/a> \u2012 Team Explorer is the client software that you use to access the Team Foundation Server functionality.<\/li>\n<li><a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/b1ef7eb2-e084-4cb8-9bc7-06c3bad9148f\" target=\"_blank\">Microsoft Visual Studio Team Foundation Server 2012 Update 1 Power Tools<\/a> \u2012 Power Tools are a set of enhancements, tools, and command-line utilities that increase productivity of Team Foundation Server scenarios.<\/li>\n<\/ul>\n<h3>Step 1: Setting up Team Foundation Service<\/h3>\n<p>Start with the sign up.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8105.hsg-12-28-12-1.png\"><img decoding=\"async\" title=\"Image of Team Foundations Service\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8105.hsg-12-28-12-1.png\" alt=\"Image of Team Foundations Service\" \/><\/a><\/p>\n<p>After the initial setup, we need to create a Project. A Project is a repository for source code and work items.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2678.hsg-12-28-12-2.png\"><img decoding=\"async\" title=\"Image of Creating New Team Project\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2678.hsg-12-28-12-2.png\" alt=\"Image of Creating New Team Project\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1526.hsg-12-28-12-3.png\"><img decoding=\"async\" title=\"Image of Create New Team Project dialog box\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1526.hsg-12-28-12-3.png\" alt=\"Image of Create New Team Project dialog box\" \/><\/a><\/p>\n<h3>Step 2: Installing and configuring Team Explorer 2012<\/h3>\n<p>You first need to <a href=\"http:\/\/www.microsoft.com\/en-au\/download\/details.aspx?id=30656\" target=\"_blank\">download Team Explorer for Microsoft Visual Studio 2012<\/a> and run the installation.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8030.hsg-12-28-12-4.png\"><img decoding=\"async\" title=\"Image of Team Explorer installation\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8030.hsg-12-28-12-4.png\" alt=\"Image of Team Explorer installation\" \/><\/a><\/p>\n<p>Open Team Explorer, and click <strong>Connect to Team Foundation Server<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5241.hsg-12-28-12-5.png\"><img decoding=\"async\" title=\"Image of Team Explorer Home\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5241.hsg-12-28-12-5.png\" alt=\"Image of Team Explorer Home\" \/><\/a><\/p>\n<p>Enter the URL of your cloud-based Team Foundation Server.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4101.hsg-12-28-12-6.png\"><img decoding=\"async\" title=\"Image of Add Team Foundation Server dialog box\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4101.hsg-12-28-12-6.png\" alt=\"Image of Add Team Foundation Server dialog box\" \/><\/a><\/p>\n<p>Now it&rsquo;s time to create a workspace mapping. Go to Source Control Explorer in Team Explorer and map your local drive. You can choose or create every folder you want.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4863.hsg-12-28-12-7.png\"><img decoding=\"async\" title=\"Image of Map dialog box\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4863.hsg-12-28-12-7.png\" alt=\"Image of Map dialog box\" \/><\/a><\/p>\n<h3>Step 3: Microsoft Visual Studio Team Foundation Server 2012 Update 1 Power Tools<\/h3>\n<p>We are going to use the Windows PowerShell cmdlets from the <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/b1ef7eb2-e084-4cb8-9bc7-06c3bad9148f\" target=\"_blank\">Microsoft Visual Studio Team Foundation Server 2012 Update 1 Power Tools<\/a> to communicate from within Windows PowerShell with Team Foundation Server.<\/p>\n<p><strong>Notes<\/strong><\/p>\n<ul>\n<li>The Windows PowerShell cmdlets need the .NET Framework 3.5 Windows Feature installed.<\/li>\n<li>Windows PowerShell Execution Policy needs to be configured. Restricted Execution Policy does not work.<\/li>\n<\/ul>\n<p>After <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/b1ef7eb2-e084-4cb8-9bc7-06c3bad9148f\" target=\"_blank\">downloading the Power Tools<\/a>, you need to install the Windows PowerShell cmdlets.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0702.hsg-12-28-12-8.png\"><img decoding=\"async\" title=\"Image of Custom Setup \" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0702.hsg-12-28-12-8.png\" alt=\"Image of Custom Setup \" \/><\/a><\/p>\n<h2>Version control steps in Windows PowerShell<\/h2>\n<p>After installing the prerequisites, you can get started with protecting your Windows PowerShell script with version control.<\/p>\n<p>Open the Windows PowerShell ISE, and then load the Team Foundation cmdlets from the Visual Studio Team Foundation Server 2012 Power Tools.<\/p>\n<p style=\"padding-left: 30px\">Get-PSSnapin &ndash;Registered<\/p>\n<p style=\"padding-left: 30px\">Add-PSSnapin Microsoft.TeamFoundation.PowerShell<\/p>\n<p>&nbsp;<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4786.hsg-12-28-12-9.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4786.hsg-12-28-12-9.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Check the commands that are available in the Microsoft.TeamFoundation.PowerShell snap in.<\/p>\n<p style=\"padding-left: 30px\">Get-Command &ndash;Module Microsoft.TeamFoundation.PowerShell<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7485.hsg-12-28-12-10.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7485.hsg-12-28-12-10.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>In this blog post, we are going to use the following cmdlets for controlling versions of your Windows PowerShell scripts.&nbsp;<\/p>\n<ul>\n<li>Get-TfssServer<\/li>\n<li>Add-TfsPendingChange<\/li>\n<li>New-TfsChangeSet<\/li>\n<li>Add-TfsPendingChange<\/li>\n<li>Get-TfsPendingChange<\/li>\n<li>New-TfsItemHistory<\/li>\n<li>Remove-TfsPendingChange<\/li>\n<\/ul>\n<div>\n<p style=\"padding-left: 60px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Check if Microsoft.TeamFoundation.PowerShell is installed<\/p>\n<p style=\"padding-left: 30px\">Get-PSSnapin -Registered<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Import Microsoft.TeamFoundation.PowerShell Snapin<\/p>\n<p style=\"padding-left: 30px\">Add-PSSnapin Microsoft.TeamFoundation.PowerShell -Verbose<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Connect to TFS Server<\/p>\n<p style=\"padding-left: 30px\">Get-TfsServer -Name &#8220;https:\/\/[name].visualstudio.com\/defaultcollection&#8221;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Create HelloWorld.ps1 file<\/p>\n<p style=\"padding-left: 30px\">New-Item C:\\DEV\\PowerShell\\HelloWorld.ps1 -ItemType File -Force<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Add File<\/p>\n<p style=\"padding-left: 30px\">#Adds files and folders from a location in the local file system to a version control server for Team Foundation.<\/p>\n<p style=\"padding-left: 30px\">Add-TfsPendingChange -Add -Item C:\\DEV\\PowerShell\\HelloWorld.ps1 -Verbose<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Check in new file<\/p>\n<p style=\"padding-left: 30px\">New-TfsChangeset -Item C:\\DEV\\PowerShell\\HelloWorld.ps1 -Comment &#8220;Initial Check in&#8221; -Verbose<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Check out for editing<\/p>\n<p style=\"padding-left: 30px\">#Makes the local file writable and changes its pending Change status to &#8220;edit&#8221; in the workspace. Edit is an alias for the Checkout command.<\/p>\n<p style=\"padding-left: 30px\">Add-TfsPendingChange -Edit -Item C:\\DEV\\PowerShell\\HelloWorld.ps1 -Verbose<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Get Pending change<\/p>\n<p style=\"padding-left: 30px\">#Displays information about pending changes to items in one or more workspaces.<\/p>\n<p style=\"padding-left: 30px\">Get-TfsPendingChange -Item C:\\DEV\\PowerShell\\HelloWorld.ps1 -Verbose<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Make changes to C:\\DEV\\PowerShell\\HelloWorld.ps1<\/p>\n<p style=\"padding-left: 30px\">Set-Content -Path C:\\DEV\\PowerShell\\HelloWorld.ps1 -Value &#8220;Hello, World&#8221;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Check in after making changes<\/p>\n<p style=\"padding-left: 30px\">New-TfsChangeset -Item C:\\DEV\\PowerShell\\HelloWorld.ps1 -Comment &#8220;Added some extra script commands&#8221; -Verbose<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Get History<\/p>\n<p style=\"padding-left: 30px\">Get-TfsItemHistory -HistoryItem C:\\DEV\\PowerShell\\HelloWorld.ps1 -Server (Get-TfsServer -name &#8220;https:\/\/[name].visualstudio.com\/defaultcollection&#8221;)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Remove Pending Change<\/p>\n<p style=\"padding-left: 30px\">#Stores a set of pending changes, together with pending check-in notes, a comment, and a list of associated work items, on the version control server for Team Foundation without actually checking them in.<\/p>\n<p style=\"padding-left: 30px\">Remove-TfsPendingChange -Item C:\\DEV\\PowerShell\\HelloWorld.ps1 -Workspace (Get-TfsWorkspace -Path C:\\DEV\\PowerShell)<\/p>\n<\/div>\n<p>Did you know that you can also load the TFS Client Assemblies to achieve the same as the Team Foundation cmdlets from the Visual Studio Team Foundation Server 2012 Power Tools?&nbsp;<\/p>\n<p style=\"padding-left: 30px\"># Load TFS Client Assembly<\/p>\n<p style=\"padding-left: 30px\">[Reflection.Assembly]::Load(&#8216;Microsoft.TeamFoundation.VersionControl.Client, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&#8217;)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Connect to TFS Server<\/p>\n<p style=\"padding-left: 30px\">[Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer(&#8220;https:\/\/[name].visualstudio.com\/defaultcollection&#8221;)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Create HelloWorld2.ps1 file<\/p>\n<p style=\"padding-left: 30px\">New-Item C:\\DEV\\PowerShell\\HelloWorld2.ps1 -ItemType File -Force<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Add File<\/p>\n<p style=\"padding-left: 30px\">#Adds files and folders from a location in the local file system to a version control server for Team Foundation.<\/p>\n<p style=\"padding-left: 30px\">$WorkstationType = [Microsoft.TeamFoundation.VersionControl.Client.Workstation]<\/p>\n<p style=\"padding-left: 30px\">$WorkspaceInfo = $WorkstationType::Current.GetLocalWorkspaceInfo(&#8220;C:\\DEV\\PowerShell&#8221;)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"># Get Collection<\/p>\n<p style=\"padding-left: 30px\">$Collection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($WorkspaceInfo.ServerUri)<\/p>\n<p style=\"padding-left: 30px\">$Collection.EnsureAuthenticated()<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"># Get Workspace. Handler for Workspace changes<\/p>\n<p style=\"padding-left: 30px\">$Global:Workspace = $WorkspaceInfo.GetWorkspace($Collection)<\/p>\n<p style=\"padding-left: 30px\">$Workspace.PendAdd(&#8220;C:\\DEV\\PowerShell\\HelloWorld2.ps1&#8221;)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Check in new file<\/p>\n<p style=\"padding-left: 30px\">$pendingChanges = $workspace.GetPendingChanges() | Where-Object {$_.LocalItem -eq &#8220;C:\\DEV\\PowerShell\\HelloWorld2.ps1&#8221;}<\/p>\n<p style=\"padding-left: 30px\">$Comment = &#8220;Initial version of the HelloWorld2.ps1 file&#8221;<\/p>\n<p style=\"padding-left: 30px\">$workspace.CheckIn($pendingChanges,$Comment)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Check out for editing<\/p>\n<p style=\"padding-left: 30px\">$Workspace.PendEdit(&#8220;C:\\DEV\\PowerShell\\HelloWorld2.ps1&#8221;)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Get Pending change<\/p>\n<p style=\"padding-left: 30px\">$pendingChanges = $workspace.GetPendingChanges() | Where-Object {$_.LocalItem -eq &#8220;C:\\DEV\\PowerShell\\HelloWorld2.ps1&#8221;}<\/p>\n<p style=\"padding-left: 30px\">$pendingChanges<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Make changes to C:\\DEV\\PowerShell\\HelloWorld2.ps1<\/p>\n<p style=\"padding-left: 30px\">Set-Content -Path C:\\DEV\\PowerShell\\HelloWorld2.ps1 -Value &#8220;Hello, World&#8221;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">#Get Tfs Item property information<\/p>\n<p style=\"padding-left: 30px\">$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($WorkspaceInfo.ServerUri)<\/p>\n<p style=\"padding-left: 30px\">$vcs = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]) #Version Control Server<\/p>\n<p style=\"padding-left: 30px\">$vcs.GetExtendedItems(&#8220;C:\\DEV\\PowerShell\\HelloWorld2.ps1&#8221;, [Microsoft.TeamFoundation.VersionControl.Client.DeletedState]::NonDeleted, [Microsoft.TeamFoundation.VersionControl.Client.ItemType]::Any)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;#Get History<\/p>\n<p style=\"padding-left: 30px\">$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($WorkspaceInfo.ServerUri)<\/p>\n<p style=\"padding-left: 30px\">$vcs = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]) #Version Control Server<\/p>\n<p style=\"padding-left: 30px\">$vcs.QueryHistory(&#8220;C:\\DEV\\PowerShell\\HelloWorld2.ps1&#8221;, [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest, 0, &#8216;None&#8217;, $null, $null, $null, 1, $false, $false)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6378.hsg-12-28-12-11.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6378.hsg-12-28-12-11.png\" alt=\"Image of command output\" \/><\/a>&nbsp;<\/p>\n<p>Have fun using Windows PowerShell and TFS to protect your Windows PowerShell scripts with version control.<\/p>\n<p>~Stefan<\/p>\n<p>Thank you, Stefan. Join me tomorrow when I will present an excerpt from my much anticipated <a href=\"http:\/\/www.amazon.com\/Windows-PowerShell-3-0-Step\/dp\/0735663394\/ref=sr_1_2?ie=UTF8&amp;qid=1355959019&amp;sr=8-2&amp;keywords=powershell+step+by+step\" target=\"_blank\">Windows PowerShell 3.0 Step by Step book<\/a>.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Guest blogger and Microsoft PFE Stefan Stranger talks about using version control to protect your Windows PowerShell scripts. Microsoft Scripting Guy, Ed Wilson, is here. Today I am pleased to present a guest blog post written by Senior Premier Field Engineer Stefan Stranger. The Scripting Wife and I were privileged to hear Stefan speak [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[331,56,3,4,393,45],"class_list":["post-4412","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-best-practices","tag-guest-blogger","tag-scripting-guy","tag-scripting-techniques","tag-stefan-stranger","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Guest blogger and Microsoft PFE Stefan Stranger talks about using version control to protect your Windows PowerShell scripts. Microsoft Scripting Guy, Ed Wilson, is here. Today I am pleased to present a guest blog post written by Senior Premier Field Engineer Stefan Stranger. The Scripting Wife and I were privileged to hear Stefan speak [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=4412"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4412\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=4412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}