Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Saturday, 22 December 2018

VS Code for PowerShell: IntelliSense Code Highlighting Not Working?

This is what VS Code looks like on _all_ machines used in the shop and elsewhere but one:

image

Note the great colour coding going on. That's IntelliSense working its magic to render the code in colour!

The errant machine looks like this:

image

Note the distinct lack of colour coding going on. :(

We removed and re-installed VS Code, the Extensions, and anything else we could with no change.

After an ask on a PowerShell list a suggestion was made to check the VS Code theme.

Sure enough, on the problematic one:

image

VS CODE: Dark (Visual Studio) Colour Theme

While on a functioning setup:

image

VS CODE: Dark+ (default dark)

For whatever reason, the latter colour theme seems to break things.

Now that we have that figured out, we can move on to coding! :D

Merry Christmas and a Happy New Year's to everyone!

Hat Tip: Shawn Melton MVP

Philip Elder
Microsoft High Availability MVP
MPECS Inc.
Co-Author: SBS 2008 Blueprint Book
www.s2d.rocks !
Our Web Site
Our Cloud Service

Tuesday, 13 November 2018

New PowerShell Guides and DISM Slipstream Process Updated

We've added two new PowerShell Guides:

We've also updated the page with some tweaks to using DISM to update images in the Install.WIM in Windows Server. The process can also be used to slipstream both Servicing Stack Updates (SSUs) and Cumulative Updates (CUs) for both Windows Server and Windows Desktop.

Thanks for reading! :)

Philip Elder
Microsoft High Availability MVP
MPECS Inc.
Co-Author: SBS 2008 Blueprint Book
www.s2d.rocks !
Our Web Site
Our Cloud Service

Wednesday, 15 August 2018

PowerShell Paradise: Installing and Configuring Visual Studio Code (VS Code) and Git

It was Ben Thomas that gave me the prodding to look into Visual Studio Code (VS Code) for PowerShell coding and troubleshooting. I had an error in a PowerShell step that puzzled me. It turned out to be the auto-replaced hyphens that got introduced into that PowerShell step somewhere along the lines since I keep (kept) everything in OneNote.

There are several reasons why coding in any form are difficult for me, suffice it to say it took a few days to get over the, "Oh no, yet something else to learn" initial reaction to that prodding.

With a little downtime late last week, the opportunity presented itself to at least do a cursory search and skim of info on VS Code and PowerShell.

What I saw amazed me so much so that the time to learn became a non-starter.

First, download VS Code but don't install it right away.

Next, download GIT for Windows (there's other versions).

Now, there's a bit of a Catch-22 in this process as Git looks for VS Code and VS Code looks for Git.

Install VS Code and Git

Install order to make things simple:

  1. Install VS Code
    • image
  2. Run VS Code and ignore the Git prompt
    • image
  3. Install Git and choose VS Code
    • image
    • This is where things can get weird. If VS Code does not get started first, the Next button will not light up!
    • If not, leave this window, start VS Code, ignore the prompt, and close it.
    • Hit the Back button and then the Next button again and the Next button on this window should now be lit up.
  4. We chose Use Git from the Windows Command Prompt
    • image
  5. On the next window Use the OpenSSL Library
  6. Checkout Windows-style, commit Unix-style line endings
    • image
  7. Use MinTTY (the default terminal of MSYS2)
    • image
  8. We left the defaults for Configuring extra options
    • Enable file system caching
    • Enable Git Credential Manager

Once Git has been installed the next thing to do is to start VS Code and it should find Git:

image

Initialize the Git Repository

A few more steps and we'll be ready to code a new PowerShell script, or transfer in from whatever method we've been using prior.

  1. Create a new folder to store everything in
    • We're using OneDrive Consumer as a location for ours to make it easily accessible
  2. CTRL+SHFT+E --> Open Folder --> Folder created above
    • VS Code will reload when the folder has been chosen
  3. CTRL+SHFT+G --> Click the Initialize Repository button
    • image
  4. Click the Initialize Repository button with the folder we opened being the default location
  5. Git should be happy
    • image

Now, we're almost there!

VS Code Extension Installation

The last steps are to get the PowerShell Extension installed and tweak the setup to use it.

  1. CTRL+SHFT+X
  2. Type PowerShell in the Marketplace search
  3. Click the little green Install button then after the install the little blue Reload button
    • image
  4. Additional VS Code Extensions we install by default
    1. Better Comments
      • Allows for colour coded # ! PowerShell Comments
    2. Git History
      • Allows us to look at what's happening in Git
    3. VSCode-Icons
      • Custom icons in VS Code

VS Code Quick Navigation

Once done, the following key strokes are the first few needed to get around and then there's one more step:

  • Source Control: Git: CTRL+SHFT+G
  • Extensions: CTRL+SHFT+X
  • Folder/File Explorer: CTRL+SHFT+E
  • User/Workspace Settings: CTRL+,

Create the Workspace

And finally, the last step is to:

  1. File
  2. Save Workspace As
  3. Navigate to the above created folder
  4. Name the Workspace accordingly
  5. Click the Save button

Then, it's Ready, Set, Code! :)

Note that the PowerShell .PS1 files should be saved in the Workspace folder and/or subfolders to work with them.

To start all new files in the PowerShell language by default add the following to User Settings

  1. CTRL+,
  2.     "files.defaultLanguage": "powershell"

One of the beauties of this setup is the ability to look at various versions of the files, much like we can with SharePoint and Office files, to compare the changes made over the history of the PowerShell Code.

Another is the ability to see in glorious colour!

image

Thanks to Ben Thomas' challenge PowerShell is already so much easier to work with!

2018-08-15 EDIT: Oops, missed one important step.

  1. Open Git GUI
  2. Click Open Existing Repository
  3. Navigate to the Workspace folder with the .git hidden folder
  4. Open
  5. Set the User's name and E-mail address for both settings
    • image
  6. Click Save

Git should be happy to Commit after that! :)

Philip Elder
Microsoft High Availability MVP
MPECS Inc.
Co-Author: SBS 2008 Blueprint Book
www.s2d.rocks !
Our Web Site
Our Cloud Service

Thursday, 9 August 2018

PowerShell: Add-Computer Error when Specifying OUPath: The parameter is incorrect FIX

We're in the process of setting up a second 2-node Kepler-64 cluster when we hit this when running the Add-Computer PowerShell to domain join a node:

Add-Computer : Computer 'S2D-Node03' failed to join domain 'Corp.Domain.Com from its current
workgroup 'WORKGROUP' with following error message: The parameter is incorrect.
At line:1 char:1
+ Add-Computer -Domain Corp.Domain.Com -Credential Corp\DomainAdmin -OUPath  …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : OperationStopped: (S2D-Node03:String) [Add-Computer], InvalidOperation
    Exception
     + FullyQualifiedErrorId : FailToJoinDomainFromWorkgroup,Microsoft.PowerShell.Commands.AddComp
    uterCommand

The PowerShell line it's complaining about is this one:

Add-Computer -Domain Corp.Domain.Com -Credential Corp\DomainAdmin -OUPath "OU=S2D-OpenNodes,OU=S2D-Clusters,DC=Corp,DC=Domain,DC-Com" -Restart

Do you see it ? ;)

The correct PoSh for this step is actually:

Add-Computer -Domain Corp.Domain.Com -Credential Corp\DomainAdmin -OUPath "OU=S2D-OpenNodes,OU=S2D-Clusters,DC=Corp,DC=Domain,DC=Com" -Restart

When specifying the OUPath option if there is any typo in that setting the nondescript error is "The parameter is incorrect."

We always prefer to drop a server or desktop right into their respective OU containers as that allows our Group Policy settings to take giving us full access upon reboot and more.

Philip Elder
Microsoft High Availability MVP
MPECS Inc.
Co-Author: SBS 2008 Blueprint Book
www.s2d.rocks !
Our Web Site
Our Cloud Service

Thursday, 31 May 2018

OS Guide: Slipstream Updates and Drivers Using DISM and OSCDImg

We've posted another guide to our Web site.

Using the script on this page in an elevated CMD allows us to take the base Install.WIM for Windows Server 2016 and slipstream the latest Cumulative Update into it.

Then, the script copies the updated Install.WIM into two separate folders where we keep two sets of installer files/folders. One is a Bare version that has only the Windows installer files. The other contains a whole host of drivers, BIOS and firmware updates, and a copy of the newly minted .ISO file. We use the FULL version for our USB flash drives (blog post) that get permanently plugged into all server systems we deploy.

This script is constantly updated.

Another will be posted at a later date that also includes the ability to update the Install.WIM file with drivers.

UPDATE 2018-06-04: Fixed the link!

Philip Elder
Microsoft High Availability MVP
MPECS Inc.
Co-Author: SBS 2008 Blueprint Book
Our Web Site
Our Cloud Service

Saturday, 9 December 2017

PowerShell TotD: Hyper-V Live Move a specific VHDX file

There are times when we need to move one of two VHDX files associated with a VM.

The following is the PowerShell to do so:

Poll Hyper-V Host/Node for VM HDD Paths

get-vm "*" | Select *path,@{N="HDD";E={$_.Harddrives.path}} | FL

Move a Select VHDX

Move-VMStorage -VMName VMName -VHDs @(@{"SourceFilePath" = "X:\Hyper-V\Virtual Hard Disks\VM-LALoB_D0-75GB.VHDX"; "DestinationFilePath" = "Y:\Hyper-V\Virtual Hard Disks\VM-LALoB_D0-75GB.VHDX"})

Move-VMStorage Docs

The Move-VMStorage Docs site. This site has the full syntax for the PowerShell command.

Conclusion

While the above process can be initiated in the GUI, PowerShell allows us to initiate a set of moves for multiple VMs. This saves on time bigtime versus mouse.

By the way, TotD means: Tip of the Day.

Thanks for reading! :)

Philip Elder
Microsoft High Availability MVP
MPECS Inc.
Co-Author: SBS 2008 Blueprint Book
Our Web Site
Our Cloud Service

Thursday, 28 January 2016

Cluster: A Simple Cluster Storage Setup Guide

In a cluster setting we have a set way to configure our shared storage whether it resides on a SOFS (Scale-Out File Server) cluster or some sort of network based storage.

First, the process to set up the storage itself:

  1. Configure the LUN
    • LUN ID must be identical for all Hyper-V nodes for SAN/NAS
  2. Connect all nodes to the storage
    • iSCSI Target for SAN/NAS
  3. Format NTFS and set OFFLINE on Node01
  4. Node2 and up ignore Initialize in Disk Management and set OFFLINE
    • This step is optional depending on the setup

When it comes to the storage we configure the following LUNs for all of our cluster setups;

  1. 1.5GB LUN
    • Set up for the Witness Disk
    • Add to Cluster Storage but NOT CSV
  2. ???GB LUN
    • Sum of all physical RAM on the nodes plus 150GB
    • Add to Cluster Shared Volumes
    • All Hyper-V nodes set to deliver VM settings files to this location
    • Don’t forget that Hyper-V writes a file that is equivalent in size for _all_ VMs running on the cluster or standalone host!
  3. Minimum 50% Storage LUN x2
    • Divide the remaining storage into two or more LUNs depending on workload and storage requirements
    • A minimum of 2 LUNs allows for storage load to be shared across the SAN’s two storage controllers, the two iSCSI networks, and the two or more Hyper-V nodes

In a SOFS setting we set up a File Share Witness for our Hyper-V compute clusters and deliver the HA shares via SMB Multichannel and a minimum of 10GbE for the VHDX files.

PowerShell

The PowerShell steps for any of the above are here to avoid copy and paste issues.

Set Default Paths:

Set-VMHost -VirtualHardDiskPath “C:\ClusterStorage” –VirtualMachinePath “C:\ClusterStorage\Volume1”

We point the VHDX setting to the CSV root just in case. Our PowerShell scripts for setting up VMs put the VHDX files into the right storage location.

Set Quorum Up:

Set-ClusterQuorum -NodeAndDiskMajority "Cluster Virtual Disk (Witness Disk)"

Philip Elder
Microsoft High Availability MVP
MPECS Inc.
Co-Author: SBS 2008 Blueprint Book

Saturday, 11 January 2014

Set Exchange 2010 and 2013 Internal and External Virtual Directory URLs in PowerShell

Here are the elevated PowerShell commands to run to set the virtual directory URLs

The elevated PowerShell commands to verify the settings:

  • Get-ActiveSyncVirtualDirectory | fl internalurl,externalurl
  • Get-AutoDiscoverVirtualDirectory | fl internalurl,externalurl
  • Get-ECPVirtualDirectory | fl internalurl,externalurl
  • Get-OabVirtualDirectory | fl internalurl,externalurl
  • Get-WebServicesVirtualDirectory | fl internalurl,externalurl

Please note that we run a split DNS setup to have the external URL map to an internal IP address while folks are in the office (as per SBS STD).

UPDATE 2014-02-14: Dave Shackelford was kind enough to point out the errors in my copy & paste methodology. The proper syntax for each Set command has been done. :)

Philip Elder
Microsoft Cluster MVP
MPECS Inc.
Co-Author: SBS 2008 Blueprint Book

Chef de partie in the SMBKitchen
Find out more at
Third Tier: Enterprise Solutions for Small Business

Tuesday, 7 January 2014

Some Hyper-V PowerShell Commands for You

Here is the command set to create a vSwitch that does _not_ share the connection with the host OS:

image

  • New-VMSwitch -Name vSwitch -NetAdapterName vSwitch -AllowManagementOS 0

Note the zero to indicate no sharing with the host OS.

The -NetAdapterName value is the name of the team we created for the VMs.

Installing features and forcing the local source files is an important thing to do otherwise one may wait a long time while the node or nodes, or a standalone host, try and pull from Microsoft's download servers only to fail much later in the game.

In this case we are installing the RSAT-Clustering feature (in our snip the -IncludeAllSubFeature is missing as we later discovered).

image

  • Install-WindowsFeature RSAT-Clustering -Source wim:d:\sources\install.wim:2 -IncludeAllSubFeature -Restart

Even with the installer pulling the needed files from the locally attached storage (flash drive) this one takes a while. We know we are successful when the node reboots.

Note that we are indicating INDEX 2 for the installer to pull from. That index is for the GUI version of the the OS. If we try and pull the source files from CORE INDEX 1 we will eventually end up with a failed result. And, given how long this process takes it is rather painful to discover just what the installer was looking for in the first place. :(

Philip Elder
Microsoft Cluster MVP
MPECS Inc.
Co-Author: SBS 2008 Blueprint Book

Chef de partie in the SMBKitchen
Find out more at
Third Tier: Enterprise Solutions for Small Business

Thursday, 11 July 2013

Server Core: PowerShell Install-WindowsFeature RSAT-Clustering Seems to Hang at 68%

On a Windows Server 2012 Core deploy we ran the following command:

  • Install-WindowsFeature RSAT-Clustering

And we saw the following for a _long_ time!

image

The “Start Installation...” line kept blinking on and off all during the time it seemed to be stuck.

With a little bit of patience we eventually saw the following result:

image

The entire process took about 15-20 minutes.

So, be patient. ;)

Philip Elder
MPECS Inc.
Microsoft Small Business Specialists
Co-Author: SBS 2008 Blueprint Book

Chef de partie in the SMBKitchen
Find out more at
www.thirdtier.net/enterprise-solutions-for-small-business/

Windows Live Writer

Monday, 9 January 2012

A Quick Way to Find Server Up-Time in Server Core or Hyper-V Server

Open an elevated command prompt and:

  1. systeminfo | find “System Boot Time:”

Our report:

C:\>systeminfo | find "System Boot Time:"
System Boot Time:          1/3/2012, 11:22:30 AM

Hat tip: Petri: Seven Simple Ways to Find Your Uptime in Windows Server 2008

Note that this command can be run on almost any Windows OS.

UPDATE: Thanks to vNiklas we have the following PowerShell command run via an elevated PowerShell session:

  1. (get-date)-([System.Management.ManagementDateTimeconverter]::ToDateTime((Get-WmiObject win32_operatingsystem).lastbootuptime)) [Enter]

Our output:

PS C:\>  (get-date)-([System.Management.ManagementDateTimeconverter]::ToDateTime((Get-WmiObject win32_operatingsystem).lastbootuptime))


Days              : 6
Hours             : 4
Minutes           : 44
Seconds           : 31
Milliseconds      : 872
Ticks             : 5354718724344
TotalDays         : 6.19759111613889
TotalHours        : 148.742186787333
TotalMinutes      : 8924.53120724
TotalSeconds      : 535471.8724344
TotalMilliseconds : 535471872.4344

Philip Elder
MPECS Inc.
Microsoft Small Business Specialists
Co-Author: SBS 2008 Blueprint Book

*Our original iMac was stolen (previous blog post). We now have a new MacBook Pro courtesy of Vlad Mazek, owner of OWN.

Monday, 30 March 2009

SBS - PowerShell 1.0 now released via WSUS

Just recently Microsoft released PowerShell 1.0 via WSUS:

09-03-30 WSUS PowerShell Released

Windows PowerShell 1.0 KB926139

PowerShell is a command line interface that provides an ability to run various management commands or script and schedule them.

It is the basis for the new Exchange 2007 Management Shell.

09-03-30 SBS 2008 - Exchange Start Menu Folder

Microsoft Exchange Server 2007 Start Menu Folder

Windows 7 and Windows Server 2008 R2 will come with version 2 of PowerShell.

While getting to know PowerShell may not be for the feint of heart, getting to know the cmdlets and how to pipe them together to form a command structure to accomplish our needed administration tasks on servers and workstations will streamline our administration tasks in the long run.

Some links for further reading:

Anything that makes our time more efficient is good for us! :)

Philip Elder
MPECS Inc.
Microsoft Small Business Specialists
Co-Author: SBS 2008 Blueprint Book

*All Mac on SBS posts will not be written on a Mac until we replace our now missing iMac! (previous blog post)

Windows Live Writer

Monday, 9 March 2009

Marco Shaw to be presenting for EMUG – Remotely :)

Our monthly Edmonton Microsoft User Group meeting is this coming Wednesday at NAIT at 18:30 (6:30PM).

Marco has a short introduction on his blog on the content we will receive:

PowerShell is the future of server management. While the management GUIs can provide us with most of the necessary management tasks, in many cases now only PowerShell gives us access to certain areas of the product being managed.

PowerShell also gives us the ability to script much of the routine tasks that would otherwise take up our valuable time clicking through the GUI management console.

This will be a worthwhile event to attend!

Bonus: Marco has a link on his blog to the LiveMeeting stream so that anyone can listen in!

Philip Elder
MPECS Inc.
Microsoft Small Business Specialists
Co-Author: SBS 2008 Blueprint Book

*All Mac on SBS posts will not be written on a Mac until we replace our now missing iMac!

Windows Live Writer

Wednesday, 18 February 2009

Some Initial Thoughts on Windows 7

We have the 7000 release of Windows 7 Ultimate x64 set up as a Hyper-V guest.

Out of the box, Windows 7 has the Hyper-V Integration Services installed so there is a time savings and a manageability improvement right there. We no longer need to install the Integration Services after the fact.

Not only that, managing and connecting to Hyper-V based VMs while connected to a Hyper-V Management capable Windows Vista desktop via RDP could be a real struggle without Integration Services being installed. Just try to connect to a Linux based VM while in a Remote Desktop Session and see what happens to mouse control in that VM as an extreme example.

The OS definitely installs quicker as a Hyper-V guest than Windows Vista Enterprise does. It is also quicker to boot and reboot.

The one hang-up we did run into was connecting the Windows 7 VM to our SBS 2003 domain.

For Windows Vista or Windows Server 2008 RTM we use the following command via an elevated command line:

  • netdom join MI-* /Domain:MySBSDomain.local /OU:OU=SBSServers,OU=Computers,OU=MyBusiness,DC=MySBSDomain,DC=local /userd:Administrator/passwordd:*

Note that in the above command line is line wrapped and the OU the system would be deposited in is the standard SBS 2003 OU for servers. We have an OU specifically for Windows Vista and now Windows 7 clients with applicable GPOs specific to those operating systems.

It turns out that the NedDom.exe command is deprecated in the Windows 7 OS. After some searching around, and subsequently asking my fellow SBS MVPs for some direction, the PowerShell Add-Computer cmdlet was the solution.

What we discovered after a lot of struggles trying to get the Add-Computer command to work was that it was broken in the 7000 build of Windows 7!

We now need to wait for the newest version of Windows 7 as the problem will be fixed in it. When the new release of Windows 7 in whatever form that takes is not really clear yet. Once it does, we will post the correct syntax for the PowerShell command.

For now, we need to settle on using the age old method of manually joining the domain and subsequently moving the computer object into the correct OU via ADUC.

Philip Elder
MPECS Inc.
Microsoft Small Business Specialists

*All Mac on SBS posts will not be written on a Mac until we replace our now missing iMac!

Windows Live Writer

Monday, 29 September 2008

Tech Days 2008 - Microsoft's investment in us ... an investment we can make in us

Tech Days 2008 Canada:

Microsoft Tech Days Canada 2008

An early bird special of 50% off the price for either the one day or two day events is on until October 15, 2008.

Here are the grids for the two day that I will be attending in Calgary:

Microsoft Tech Days Day 1

The two tracks that I will be focused on are the Virtualization and the Infrastructure ones.

The decision for which session is going to be tough too, especially with the last one being a tie between SoftGrid application virtualization (MPECS Inc. and our clients are on Vista SA which includes SoftGrid) and the PowerShell and WMI session for the Infrastructure track.

For now, PowerShell and WMI will win out, with the ultimate decision being made when I can find out a bit more about the meat and potatos in each session.

Sessions registered for:

  • Planning Successful Physical to Virtual Server Migrations with the Microsoft Assessment and Planning Toolkit.
  • Streamlining Administration of Your Active Directory Deployments Using Group Policy Preferences, Templates, and Scripting.
  • Managing Your Virtual Infrastructure Using System Center Virtual Machine Manager 2008.
  • Automating the Management of Windows Servers using PowerShell and Windows Management Instrumentation (WMI).

The second day grid:

Microsoft Tech Days Day 2

The sessions that I will be registered for:

  • Successful Migration Techniques For Migrating To Microsoft Exchange Server 2007.
  • Windows Deployments the Way You Want Them: Unleashing the Power of the Microsoft Deployment Toolkit with Customization.
  • Security in a Virtual World - How to Lock Down Your Virtual Environments.
  • Virtualization Chalk Talk.

Many of these sessions are directly applicable to the infrastructure solutions we have and are putting together for our clients and for our own company.

There is no replacement for taking the time to sit in the presence of experts who are demonstrating the abilities and features of the various products we work with.

Training, especially training that we pay for, is a very valuable part of our professional development. We work in an industry where things are constantly evolving and out right changing. Training is both an investment in our clients and our own businesses.

We cannot afford to sit on our laurels with what we believe to be a good knowledgebase and experience base in our heads and hands. Doing so places our client's infrastructure and thus their livelihoods at risk. We are responsible to provide our clients with the best possible solution to fit their business needs.

That infrastructure solution is not necessarily the one we think is the best, but the one that will be made up of hardware and software products that will best fit for them. If we don't know the products, then we either get to know them or get someone who does know them involved to collaborate with us in providing the solution.

Philip Elder
MPECS Inc.
Microsoft Small Business Specialists

*All Mac on SBS posts are posted on our in-house iMac via the Safari Web browser.

Thursday, 21 August 2008

SBS 2008 and Custom Reports - Share yours ...

Looking for a small way to help the greater SBS community?

Then the SBS Code Plex is for you.

The site has been put together for people to share their custom report queries they have created for SBS 2008. Susan Bradley has left an email address on the site to get in touch with her so that you too can contribute code.

You will need to register with the site and include your CodePlex username in the email to Susan in order for her to add you to the group of contributors.

For SBS 2008 reporting, a lot has changed. And, one of the most significant changes is the ability to really work those reports to put out information that is very relevant to our particular client environment.

Links:
For those of us who are not into coding, this new development on the SBS front will be a little daunting. So, check out the code that has been shared on the site so that you can get familiar with the code structure.

After creating a few custom queries, they should come fairly easy.

Also, this is a good way to get comfortable with getting introduced to PowerShell if you have not seen it yet!

And, of course, feel free to download the code and implement it on your SBS 2008 installations as you require!

Way to go SBSers!

Philip Elder
MPECS Inc.
Microsoft Small Business Specialists

*All Mac on SBS posts are posted on our in-house iMac via the Safari Web browser.