标签: powershell

重新启用导入模块 Psreadline 警告

这个警告在 Visual Code 应用程序的终端中不断弹出

Warning: PowerShell detected that you might be using a screen reader and has
         disabled PSReadLine for compatibility purposes.
         If you want to re-enable it, run 'Import-Module PSReadLine'.
Run Code Online (Sandbox Code Playgroud)

即使我将值更改为0via regedit,警告仍然显示。

powershell warnings screen-readers visual-studio-code

3
推荐指数
1
解决办法
2568
查看次数

无法将字符串转换为布尔值 - 在 linux 上可以使用 powershell

我阅读了有关如何将布尔值传递给 Linux 上的 powershell 参数的整个线程。没有什么对我有用。

我在 Ansible 中的代码如下:

- name: Install PowerCLI
  shell: pwsh -Command "Set-PowerCLIConfiguration -Scope AllUsers -ParticipateInCEIP:$False -Confirm:$False -InvalidCertificateAction Ignore"
Run Code Online (Sandbox Code Playgroud)

我使用了许多变体,例如-ParticipateInCEIP:False, or -ParticipateInCEIP False, or -ParticipateInCEIP $false,但我总是得到相同的错误,它期望布尔值,但我发送了字符串。

我正在对安装了 Powershell 的 Linux 机器运行这个 Ansible 任务。

有关如何使其工作的任何提示?

最好的事物,

弗朗西斯

linux powershell ansible

3
推荐指数
1
解决办法
46
查看次数

在 Powershell 中使用升级的 FolderBrowserDialog(“Vista 风格”)

我正在使用PowerShell使用户能够浏览 Node.js 应用程序的文件/文件夹路径(因为到目前为止我还没有找到更好的轻量级替代方案),而且我遇到了处理问题的古老麻烦具有FolderBrowserDialog不支持的可怕的、糟糕的可用性:

  • 粘贴路径
  • 访问快速访问项目
  • 改变看法
  • 排序或过滤项目
  • 等等...

糟糕的对话

标准脚本如下所示:

Function Select-FolderDialog($Description="Select Folder", $RootFolder="MyComputer"){
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null     
        
    $objForm = New-Object System.Windows.Forms.FolderBrowserDialog
    $objForm.RootFolder = $RootFolder
    $objForm.ShowNewFolderButton = $true
    $objForm.Description = "Please choose a folder"
    $Show = $objForm.ShowDialog()
    If ($Show -eq "OK")
    {
        Return $objForm.SelectedPath
    }
    Else
    {
        Write-Error "Operation cancelled by user."
    }
}
$folder = Select-FolderDialog
write-host $folder
Run Code Online (Sandbox Code Playgroud)

我过去曾使用Windows API CodePack for C# Windows Forms 应用程序创建了一个CommonOpenFileDialogwith IsFolderPicker = true,为我OpenFileDialog提供了易于使用的托管文件夹浏览器的功能和可访问性。 更好但非标准的对话

在我在这里寻找使用类似内容的方法时,我了解到常规的 FolderBrowserDialog …

.net powershell winforms

3
推荐指数
1
解决办法
249
查看次数

你怎么称呼这些?[数组][字符串][整数]

这些叫什么?在 powershell 中编写脚本时,我可以使用它们来设置或转换变量的数据类型,但是这个术语是什么?这些有官方文档吗?

例子:

$var = @("hello","world")
If ($var -is [array]) { write-host "$var is an array" }
Run Code Online (Sandbox Code Playgroud)

.net powershell terminology

3
推荐指数
1
解决办法
100
查看次数

在 oneliner 中删除 ConvertFrom-StringData 之后的重复项

例如,我有这个班轮:

get-process | select id, processname | %{$_.processname +"="+ $_.id} | ConvertFrom-StringData

它返回每个进程及其 id 的键和值对。我的目标是删除任何具有重复名称的进程,并只留下其中一个(例如,我想只留下一个 svchost 条目),放在一个班轮中。似乎没有什么对我有用,我不确定这ConvertFrom-StringData是正确的方向,并且不明白它如何成功将其转换为具有重复键的哈希表。

powershell hashtable duplicates

3
推荐指数
1
解决办法
78
查看次数

powershell Get-ChildItem 结果在数组中

(Get-ChildItem -File -Recurse -Path $path).Fullname 返回全名 (Get-ChildItem -File -Recurse -Path $path).Name 数组返回文件名数组但 (Get-ChildItem -File -Recurse -Path $path).Length只返回一个值 - 元素数

问题 - 如何将结果作为文件长度数组?

arrays powershell object member-enumeration

3
推荐指数
2
解决办法
148
查看次数

为什么 Powershell 可以访问较新的 .net 版本中引入的方法?

Powershell v5.1 似乎使用 .Net Framework v4.0

[Environment]::Version
# Major  Minor  Build  Revision
# -----  -----  -----  --------
# 4      0      30319  42000
Run Code Online (Sandbox Code Playgroud)

和DateTimeOffset.FromUnixTimeSeconds方法需要 .Net Framework v4.6+ ,所以基本上 Powershell v5.1 不应该访问它。但 ...

[DateTimeOffset]|Get-Member -Static -Name FromUnixTimeSeconds
# TypeName: System.DateTimeOffset
# Name                MemberType Definition
# ----                ---------- ----------
# FromUnixTimeSeconds Method     static System.DateTimeOffset FromUnixTimeSeconds(long seconds)
Run Code Online (Sandbox Code Playgroud)

为什么我可以调用它?它与 C# AssemblyVersion 和 AssemblyFileVersion 有关系吗?

powershell

3
推荐指数
1
解决办法
81
查看次数

仅获取 Anaconda Powershell 中的 IP 地址

我只想在 Windows 的 Anaconda Powershell 中获取我的 Ip 地址的输出。

curl https://ipinfo.io/ip
Run Code Online (Sandbox Code Playgroud)

给了我以下内容:

    StatusCode        : 200
    StatusDescription : OK
    Content           : 22.031.123.456
    RawContent        : HTTP/...
                        ...
                        ...
                    ...
                    ...
                    Content-Type: text/html; charset=utf-8
                    Date: ...
                    Via:...
Forms             : {}
Headers           : {[..., *], [...], [...],
                    [..., ...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : ...
RawContentLength  : ...
Run Code Online (Sandbox Code Playgroud)

如您所见,“内容”显示了我的 IP 地址。但是如果没有任何其他信息,我无法获得 IP 地址。

注意:“curl api.ipify.org”和“curl ipinfo.io/ip”和其他人正在做完全相同的事情。

windows powershell curl ip-address anaconda

3
推荐指数
1
解决办法
64
查看次数

PowerShell - 调用在另一个函数中创建的函数

当我运行这个:

function Setup-One{

    function First-Function{
    Write-Host "First function!"
    }

    function Second-Function{
    Write-Host "Second function!"
    }
}
Setup-One
Run Code Online (Sandbox Code Playgroud)

然后我打电话给First-Functionor Second-Function,PS 说它们不存在。我究竟做错了什么?

windows powershell scope function

3
推荐指数
1
解决办法
44
查看次数

仅使用 powershell,对 300 行的文本文件进行排序,首先按字符串长度排序,然后在达到该长度后,将它们全部按字母顺序设置

我正在尝试将其作为 powershell 中的单行代码来执行,以便我可以继续根据检查字符串检查这些字符串。我遇到的麻烦是,无论我做什么,我都只能通过字符串长度进行设置。

以下尝试未能获得所需的结果。一个文本很好,另一个成功。我也试过用管道输入它们,但我相信它们都不接受管道输入。

感谢您的帮助,因为我是 powershell 的新手。

PS C:\Users\IEUser> Get-Content Desktop/dict.txt | Sort-Object 
PS C:\Users\IEUser> Get-Content Desktop/dict.txt | Sort-Object -Property Length 
Run Code Online (Sandbox Code Playgroud)

powershell

3
推荐指数
1
解决办法
71
查看次数