PowerCli Core Fling for MAC! How-to guide.

At VMworld 2016 in Las Vegas I attended the session INF8260 – Automated Deployment and Configuration of the vCenter Server Appliance which was presented by Alan Renouf and William Lam.  If you have not view this then I highly recommend you do so.  During the session Alan briefly touched on the ability to run PowerCLI on MAC and Linux which was very exciting news and without much delay the Fling was release 2 days ago:

https://labs.vmware.com/flings/powercli-core

PowerCLI Core uses Microsoft PowerShell Core and .Net Core to enable users of Linux, Mac and Docker to now use the same cmdlets which were previously only available on windows. Crazy right!? Well we have Microsoft to thank for making Powershell opensource and available for Linux and MAC

Below are my instructions on how I setup PowerCLI core to work on my MAC.

Step 1:   Download and Install .NET Core for Mac OS X from here

  • Install pre-requisites
    • In order to use .NET Core, we first need to install the latest version of OpenSSL. The easiest way to get this is from Homebrew.(Homebrew installs the stuff you need that Apple didn’t.)
  • Run the following command to install Homebrew:
    • # /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
    •  After installing brew, run the following commands:
      • # brew update
      • # brew install openssl
      • # ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
      • # ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
  • Install .NET Core SDK
    • Download and install the official installer.
    • This installer will install the tools and put them on your PATH so you can run dotnet from the Console
    • Screen Shot 2016-10-18 at 8.57.10 PM.png
    • Screen Shot 2016-10-18 at 8.57.16 PM.png
    • Screen Shot 2016-10-18 at 8.57.22 PM.png
    • Screen Shot 2016-10-18 at 8.58.21 PM.png

Step 2:   Download and Install PowerShell for Mac OS X

  • https://github.com/PowerShell/PowerShell
  • Click “Clone or Download” -> Download Zip
  • Extract the Zip file
  • Installation doc can be found here:  docs/installation/linux.md#macos-1011
  • Download the PKG package powershell-6.0.0-alpha.11.pkg from the releases page onto the macOS machine.
    • Either double-click the file and follow the prompts, or install it from the terminal:  # sudo installer -pkg powershell-6.0.0-alpha.11.pkg -target /
  • You might get the error if your security settings have allowed apps only from App store and identified developers.
  • Screen Shot 2016-10-19 at 9.21.48 AM.png
  • Click OK
  • Go to MAC System Preferences
  • Security and Privacy
  • Unlock
  • Screen Shot 2016-10-19 at 9.25.59 AM.png
  • The powershell-6.0.0-alpha.11.pkg will show and you can click “Open Anyway”
  • Screen Shot 2016-10-19 at 9.26.23 AM.png
  • Screen Shot 2016-10-19 at 9.26.28 AM.png
  • Screen Shot 2016-10-19 at 9.26.41 AM.png

 

Step 3:  Perform the following steps to ensure you are using the latest OpenSSL and Curl

  • # brew install openssl
  • # brew install curl –with-openssl
  • Screen Shot 2016-10-19 at 9.38.59 AM.png
  • Since we installing 6.0.0-alpha.11, make sure you folder is updated correctly.
  • # sudo install_name_tool -change /usr/lib/libcurl.4.dylib /usr/local/opt/curl/lib/libcurl.4.dylib /usr/local/microsoft/powershell/6.0.0-alpha.11/System.Net.Http.Native.dylib
  • # sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/microsoft/powershell/6.0.0-alpha.11/System.Security.Cryptography.Native.dylib

Step 4: Verify directoy /.local/share/powershell/Modules exists

  • If the directory does not exist, then create it by running the following commands:
    • # mkdir -p ~/.local/share/powershell/Modules

Step 5:  Extract the PowerCLI modules

  • Download the module zip file from:
  • Extract the PowerCLI modules into the directory you created above by running the following command:
  • # unzip PowerCLI.ViCore.4523941.zip -d ~/.local/share/powershell/Modules
  • # unzip PowerCLI.Vds.4523941.zip -d ~/.local/share/powershell/Modules

 

Step 6: Launch PowerShell

  • Open terminal
  • Start Powershell in the terminal by running the following command:
    • # powershell
  • Import the PowerCLI Modules into your PowerShell Session:
    • PS > Get-Module -ListAvailable PowerCLI* | Import-Module
  • Connect to your vCenter Server using Connect-VIServer
    • PS> Connect-VIServer -Server 10.20.30.10 -User administrator@vSphere.local -Password Vmware!
  • I received  a WARNING when trying to connect:  “Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to

    Prompt if you’d like to connect once or to add a permanent exception for this server”

    • Best is to avoid the warning all together, with an official certificate or a self-signed certificate or run the following command:
      • PS >  Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
    • Screen Shot 2016-10-19 at 10.00.49 AM.png
  • Now you should connect successfully to your vCenter server from MAC!

 

Links:

https://labs.vmware.com/flings/powercli-core

https://github.com/PowerShell/PowerShell/

https://blogs.vmware.com/PowerCLI/2016/10/powercli-core-fling-available.html

 

DPA – Automate the conversion of report from CSV to Excel and upload to Sharepoint

Data Protection Advisor is a great application providing alerts and reports.

I created a scheduled custom report to show daily backups from Avamar.  The report job however only saves to CSV and cannot export file to a share.  You can publish to Sharepoint but this only compatible with Sharepoint Server 2013 so this was not an options for us.

I create a batch file which copies the CSV file from the website using wget.
I then run a powershell script to convert the CSV file to XLSX.
Thanks to Boe Prox – https://gallery.technet.microsoft.com/office/7c56c444-2476-4625-b1d9-821f30280e44
After conversion is completed the file is copied to a Sharepoint document library.
I then setup a windows task scheduler to run the batch file.

A couple of problems I ran into:

On a windows 2008 R2 server when trying to open the Sharepoint document library in windows explorer gives you the following error message:

“your client does not support opening this list with windows explorer”
To resolve this:
Install Desktop Experience on Windows 2008 R2
Go to features -> Add features -> Select “Desktop experience”
When i ran the batch file from windows task scheduler I got the following error “Microsoft Excel cannot access the file”. 
To resolve this:
You have to create a folder (or two on a 64bit-windows):
(32Bit, always)
C:\Windows\System32\config\systemprofile\Desktop
(64Bit)
C:\Windows\SysWOW64\config\systemprofile\Desktop
Task scheduler failed to copy the file to mapped network drive
To resolve this:
Changed the copy to UNC path
Solution:  (can copy and paste into batch file)

“C:\Program Files (x86)\GnuWin32\bin\wget” -N –http-user= –http-password= –no-check-certificate –secure-protocol=sslv3 https://:9002/dpa-api/scheduledreport/results/DailyBackups.csv
sleep 5
powershell -NoProfile -command “. .\ConvertCSV-ToExcel.ps1”; “” > E:\DPAreports\convert.log
sleep 5
copy /Y “E:\DPAreports\Daily Backup Report.xlsx” “\\@SSL\DavWWWRoot\DPA Reports” > E:\DPAreports\copy.log