我正在尝试在Azure中自动化DataGateway,最近在powershell 7中发布了管理它的库。但是Azure DSC与Windows Powershell 5一起工作的问题,即使VM安装了Powershell 7,它也不起作用。
有人能建议一个合适的方法吗?
启用执行策略:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
安装最新版本的NuGet和PowerShellGet
Install-PackageProvider Nuget -MinimumVersion 2.8.5.201 -Force | Out-Null
Install-Module -Name PowerShellGet -Force -AllowClobber
创建Foo文件夹
$LFHT = @ {
ItemType = 'Directory'
ErrorAction = 'SilentlyContinue'}
New - Item - Path C: Foo@ LFHT | Out - Null
这些命令使用称为splatting的PowerShell技术。有关详细信息,您可以键入:
Get-Help about _ splattin
下载PowerShell 7安装脚本
Set-Location C:Foo
$URI = "https://aka.ms/install-powershell.ps1"
Invoke-RestMethod -Uri $URI |
Out-File -FilePath C:FooInstall-PowerShell.ps1
查看安装文件帮助信息
Get-Help -Name C:FooInstall-PowerShell.ps1
正在安装PowerShell 7
$EXTHT = @ {
UseMSI = $true
Quiet = $true
AddExplorerContextMenu = $true
EnablePSRemoting = $true}
C:FooInstall-PowerShell.ps1 @EXTHT
下载PowerShell 7 MSI安装包的安装脚本然后以静默方式运行此代码。
运行以打开PowerShell 7控制台的可执行程序的名称为pwsh.exe。
另一个明显的区别是PowerShell 7没有.PS1XML文件。
检查安装文件夹
Get-Childitem -Path $env:ProgramFilesPowerShell7 -Recurse |
Measure-Object -Property Length -Sum
查看模块文件夹位置
$I = 0
$env:PSModulePath -split ';' |
Foreach-Object {
"[{0:N0}] {1}" -f $I++, $_}
查看配置文件位置:
ISE 内部
$PROFILE |
Format-List -Property *Host* -Force
从Windows PowerShell控制台
powershell -Command '$Profile| Format-List -Property *Host*' -Force
正在启动PowerShell 7
打开pwsh.exe,然后按Enter键打开PowerShell 7控制台。打开PowerShell 7控制台后,通过查看$PSVersionTable变量来验证版本
$PSVersionTable
查看模块文件夹的新位置
$ModFolders = $Env:PSModulePath -split ';'
$I = 0$
ModFolders |
ForEach-Object {"[{0:N0}] {1}" -f $I++, $_}
查看配置文件的新位置
$PROFILE | Format-List -Property *Host* -Force