azure - 带有 PowerShell 7 的 Azure DSC
问题描述
我正在尝试在 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:\Foo\Install-PowerShell.ps1
查看安装文件帮助信息
Get-Help -Name C:\Foo\Install-PowerShell.ps1
安装 PowerShell 7
$EXTHT = @ {
UseMSI = $true
Quiet = $true
AddExplorerContextMenu = $true
EnablePSRemoting = $true}
C:\Foo\Install-PowerShell.ps1 @EXTHT
下载 PowerShell 7 MSI 安装包的安装脚本然后静默运行此代码。
为调出 PowerShell 7 控制台而运行的可执行程序的名称是 pwsh.exe。
另一个明显的区别是 PowerShell 7 没有 .PS1XML 文件。
检查安装文件夹
Get-Childitem -Path $env:ProgramFiles\PowerShell\7 -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
推荐阅读
- java - 如何使用 GSON 或任何其他序列化程序将其解析为 POJO 模型
- powerbi - Microsoft PowerBI 匹配多个值是使用 ID 和日期的单独表
- javascript - 如何在不刷新页面的情况下更改 URL?
- c# - Google Calendar API 异常“访问被拒绝。” .NET Core Web App 在本地运行良好,在 Azure 上发布时引发异常
- reactjs - 将函数传递给孩子的子组件
- python - 对熊猫数据字段的速记引用?
- python - 遍历数据块并为该块中的每个元素再次迭代
- python - Discord.py 授予用户对文本频道的权限
- java - 我如何知道在通知中单击了哪个按钮?
- jquery - 如何检查输入数字是否在多个数字Jquery之间?