Azure DSC with PowerShell 7

430 views Asked by At

I am trying to automate DataGateway in Azure and recently in powershell 7 were released library to manage it. But the problem that Azure DSC working with Windows Powershell 5 and even if VM have installed powershell 7 it's not working.

Can someone suggest a proper way to do it?

1

There are 1 answers

0
Mehdi On

Enabling the Execution Policy:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force

Installing the Latest Version of NuGet and PowerShellGet

Install-PackageProvider Nuget -MinimumVersion 2.8.5.201 -Force | Out-Null
Install-Module -Name PowerShellGet -Force -AllowClobber 

Creating the Foo Folder

$LFHT = @ {
ItemType = 'Directory'
ErrorAction = 'SilentlyContinue'}


New - Item - Path C: \Foo@ LFHT | Out - Null

These commands use a PowerShell technique known as splatting. for more information, you can type:

 Get-Help about _ splattin

Downloading the PowerShell 7 Installation Script

Set-Location C:\Foo
$URI = "https://aka.ms/install-powershell.ps1"
Invoke-RestMethod -Uri $URI | 
Out-File -FilePath C:\Foo\Install-PowerShell.ps1

Viewing Installation File Help Information

Get-Help -Name C:\Foo\Install-PowerShell.ps1

Installing PowerShell 7

$EXTHT = @ {
UseMSI = $true
Quiet = $true
AddExplorerContextMenu = $true
EnablePSRemoting = $true}


C:\Foo\Install-PowerShell.ps1 @EXTHT

The installation script that downloads the PowerShell 7 MSI Installation package then runs this code silently.

the name of the executable program you run to bring up the PowerShell 7 console is pwsh.exe.

Another noticeable difference is that with PowerShell 7, there are no .PS1XML files.

Examining the Installation Folder

Get-Childitem -Path $env:ProgramFiles\PowerShell\7 -Recurse |
Measure-Object -Property Length -Sum

Viewing Module Folder Locations

 $I = 0
$env:PSModulePath -split ';' |  
Foreach-Object { 
"[{0:N0}]   {1}" -f $I++, $_}

Viewing Profile File Locations:

Inside the ISE

$PROFILE |
Format-List -Property *Host* -Force

from Windows PowerShell Console

powershell -Command '$Profile|   Format-List -Property *Host*' -Force

Starting PowerShell 7

Open pwsh.exe, and hit Enter to open a PowerShell 7 console. After you open the PowerShell 7 console, verify the version by viewing the $PSVersionTable variable

$PSVersionTable

Viewing New Locations for Module Folders

$ModFolders = $Env:PSModulePath -split ';'
$I = 0$
ModFolders | 
ForEach-Object {"[{0:N0}]   {1}" -f $I++, $_}

Viewing New Locations for Profile Files

$PROFILE | Format-List -Property *Host* -Force