我已经安装了 powershell PKG 文件,我可以从应用程序启动 powershell 
但是,我想将它集成到 Mac 上的终端中。
根据此链接,安装 pkg 文件后,我应该能够powershell在终端上运行命令并切换到 PS 模式。
我有一个安装了 Powershell Core 6.1.2 的 Ubuntu 18.04 VM,我想将其更新到最新的 PowerShell Core 版本。
我怎么做?
我是否按照https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-6#ubuntu-1804上的安装说明进行操作并安装最新版本版本在旧版本之上?
是否要先删除旧版本,然后再安装新版本?你是怎样做的?
Powershell Core 中是否有工具可以执行更新?
我正在尝试使用 Azure-CLI(使用 Powershell Core)通过变量添加多个标签。
az resource tag --tags ${tagsToAdd} --id $resource.id
在哪里 $tagsToAdd="a=b c=d"
但这只给了我一个标签:
"tags": {
"a": "b c=d"
}
Run Code Online (Sandbox Code Playgroud)
这有什么问题?az resource tag --tags a=b c=d --id $resource.id正确使用会产生两个标签。
我正在尝试使用 Pester for PowerShell 来测试我的一些代码,但我无法让 Pester 处理与错误相关的工作。
以这个非常基本的例子为例 -
using module AccessTokenRequestModel
InModuleScope -ModuleName AccessTokenRequestModel -ScriptBlock {
### Create a new instance of the 'AccessTokenRequest' object.
$request = [AccessTokenRequest]::new()
Describe -Name "the 'AccessTokenRequest' module -" -Tags @("AccessTokenRequest","Get","Unit") -Fixture {
It "Given a valid organisation, the 'GetAccessToken' method should return a valid Access Token entity." {
$accessTokenEntity = $request.GetAccessToken("ValidOrg")
$accessTokenEntity.PartitionKey | Should be "AccessToken"
$accessTokenEntity.RowKey | Should be "ValidOrg"
$accessTokenEntity.AccessToken | Should be "12345"
}
It "Given an invalid organisation, the …Run Code Online (Sandbox Code Playgroud) 对我的机器进行一些更改后,Powershell 失败,因为 $PROFILE 变量指向与以前不同的位置,即它设置为
C:\Powershell\Microsoft.PowerShell_profile.ps1
Run Code Online (Sandbox Code Playgroud)
代替
C:\Users\user\Documents\Powershell\Microsoft.PowerShell_profile.ps1
Run Code Online (Sandbox Code Playgroud)
这会导致诸如找不到已安装模块等问题。所以我的问题是Powershell如何设置$PROFILE的值?可以改变吗?
电源外壳:
$file = "text.txt"
Test-Path $file
# True
Get-Location
# C:\Users\Fors1k
[IO.File]::OpenRead($file)
# FileStream
[IO.FileInfo]::new($file)
# Mode LastWriteTime Length Name
# ---- ------------- ------ ----
# -a---- 05.03.2021 18:12 7 text.txt
gc $file
# test123
Run Code Online (Sandbox Code Playgroud)
一切都好。
PowerShell 核心:
$file = "text.txt"
Test-Path $file
# True
Get-Location
# C:\Users\Fors1k
[IO.File]::OpenRead($file)
# Exception calling "OpenRead" with "1" argument(s): "Could not find file 'C:\Windows\system32\text.txt'."
[IO.FileInfo]::new($file)
# Mode LastWriteTime Length Name
# ---- ------------- ------ ----
# larhs 01.01.1601 3:00
gc $file
# test123 …Run Code Online (Sandbox Code Playgroud) 我对 Powershell 非常陌生,我正在尝试为脚本文件中的两个参数添加默认值,但在执行时仍然要求我输入缺少的参数。
参数是
param(
[string]
$Build = "production",
[bool]
$Deploy = 1
)
Run Code Online (Sandbox Code Playgroud)
所以当我这样做时,./script.ps1 -Build我收到一个错误
/Users/akshayrajgollahalli/GitHub/gollahalli.com/script.ps1 : Missing an argument for parameter 'Build'. Specify a parameter of type 'System.String' and try again.
Run Code Online (Sandbox Code Playgroud)
但根据微软博客,这就是我正在做的。我不确定这里有什么错误。
更新 1:
另一种情况是我可能想要类似的东西./script.ps1 -Build local应该覆盖该production值。
powershell ×7
.net ×1
.net-core ×1
azure-cli ×1
git ×1
macos ×1
pester ×1
ubuntu ×1
ubuntu-18.04 ×1