标签: powershell

PIL:模块对象没有属性“调整大小”

我正在尝试 PIL,它抛出了一个我觉得很奇怪的错误。

这是我所有的代码:

from PIL import Image, ImageOps

im = ("lenna.png")
imResize = Image.resize((200,200), Image.ANTIALIAS)
Run Code Online (Sandbox Code Playgroud)

我通过 Windows Powershell 在命令行上执行此操作,前两条语句没有给我带来任何问题。事实上,我什至尝试过im.show()并打开了图像,但是当我尝试时imResize,出现以下错误:

AttributeError: 'module' object has no attribute 'resize'
Run Code Online (Sandbox Code Playgroud)

然而,当我浏览时,help(Image)我可以看到resize那里的方法,而且我似乎一切都做得很好。

请问我还缺少什么吗?谢谢

powershell image python-imaging-library python-2.7

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

如何将单个 PowerShell 输出字符串放入 cmd 变量?

我有一个输出单个字符串值的 PowerShell 脚本。我有一个 cmd 批处理脚本,需要执行 PowerShell 脚本并将单个 PowerShell 输出值放入批处理脚本中的变量中。我正在寻找各种导出到文件或读取文件的方法,但这不是我想要的。谢谢!

(编辑)这是我尝试使用它的地方(响应发布脚本):

@echo off
REM The next line puts the .ps1 output into the variable
REM and, obviously, this does not work
set pass_word=<C:\temp\PullPassword.ps1
tabcmd login -s "http://myserver.net" -u mylogon -p %pass_word%
Run Code Online (Sandbox Code Playgroud)

(编辑)我在这里看到了OP的答案Getting Powershell variable value in batch script,还查看了foxdrive的答案,所以我开始使用FOR...DO语句。我认为我对 cmd 非常擅长,但不明白为什么我的命令不起作用:

for /f "delims=" %%a in ('powershell . "C:\temp\PullPassword.ps1"') do set val=%%a
echo  %a% 
Run Code Online (Sandbox Code Playgroud)

当我在另一篇文章中查看 Foxdrive 的完整答案时,我震惊了:%a% 是错误的,我需要 %val%!噢,耻辱!以下作品:

@echo off
set mypath=C:\temp\PullPassword.ps1
for /f "delims=" %%a in ('powershell . …
Run Code Online (Sandbox Code Playgroud)

powershell cmd batch-file

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

(PowerShell) 使用转义分隔符分割字符串

split模块通常用于将 Active Directory 可分辨名称和规范名称拆分为 RDN,从而方便地忘记可能在 OU 和 CN 中使用的转义分隔符,如下所示:

\n\n

带有转义逗号的专有名称示例:

\n\n
CN=Test User,OU=Comma\\,Test,OU=Test,DC=domain,DC=com\n
Run Code Online (Sandbox Code Playgroud)\n\n

带有转义斜杠的规范名称示例:

\n\n
Domain.com/Test/Slash\\/Test/Test User\n
Run Code Online (Sandbox Code Playgroud)\n\n

互联网上有几个分裂的例子,甚至没有提到这个陷阱,它可能会工作很长时间,但迟早会给解决这个编程缺陷带来很多痛苦。

\n\n

我不\xe2\x80\x99t 认为有一种简单的方法可以使用正则表达式正确分割转义字符串(另请参阅:是否存在包含转义序列的字符串的纯正则表达式分割?)。\n。

\n

powershell split escaping character

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

创建 RunSpace 时如何使用 PowerShell 2 或 3?

在安装了 PowerShell 2.0 和 PowerShell 3.0 的计算机上,创建 RunSpace 时如何选择从 C# 应用程序启动哪个?

似乎有各种各样的配置参数,但没有一个控制启动哪个版本的PowerShell。我可以想象它可能基于用于调用进程的 .NET 版本,但是当您调用 RunspaceFactory.CreateOutOfProcessRunspace 时会怎么样?既然如此,应该没什么关系吧?

.net c# powershell runspace

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

在 Windows 上通过别名将 git hist 设置为漂亮的打印日志

这样做:

git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
Run Code Online (Sandbox Code Playgroud)

正如在 Windows 机器上提到的那样,只给了我这个错误:

usage: git config [options]
Run Code Online (Sandbox Code Playgroud)

当我尝试跑步时git hist。有什么建议吗?为什么它不起作用?

windows git powershell

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

如何使用 PowerShell 将人类可读时间戳转换为 Unix 时间戳?

我有一个以下csv文件格式,其中包含一些工具信息和正常时间。

“工具”,“TimeRaished”“Abod”,“2014 年 6 月 27 日上午 8:32:45”“测试”,“2014 年 6 月 27 日上午 8:30:42”“分组”,“2014 年 6 月 27 日- 14 8:22:01 AM" "Tize","27-Jun-14 8:15:50 AM" "COrd","27-Jun-14 8:00:52 AM"

我想使用 PowerShell cmdlet将正常时间转换为Unix时间戳格式。但我不知道该使用哪个 powershell cmdlet。

unix powershell timestamp unix-timestamp

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

Powershell 模块清单“ScriptsToProcess”

我正在编写一个 powershell 模块,我好奇但有点不清楚的一件事是 ScriptsToProcess 键。如果我的某些功能可能依赖于上述某些要求,我是否可以或应该使用它来验证某些内容,例如操作系统类型、位类型或某些环境变量是否存在,以引发警告?

powershell

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

Powershell:按子节点值的元素对xml进行排序

如何使用 Powershell 按“元组”列表(键入的“整数”)的第二个节点对该 xml 进行降序排序。

因此结果将是 xml,但第一个元素将是 COMPUTERSF34,然后是 COMPUTER123..

   <Result>
                <Tuple>
                    <Answer type="string">COMPUTERSF34</Answer>
                    <Answer type="integer">93</Answer>
                </Tuple>
                <Tuple>
                    <Answer type="string">NYCCOMPUTER01</Answer>
                    <Answer type="integer">44</Answer>
                </Tuple>
                <Tuple>
                    <Answer type="string">COMPUTER_05</Answer>
                    <Answer type="integer">45</Answer>
                </Tuple>
                <Tuple>
                    <Answer type="string">COMPUTER56</Answer>
                    <Answer type="integer">38</Answer>
                </Tuple>
                <Tuple>
                    <Answer type="string">COMPUTER123</Answer>
                    <Answer type="integer">51</Answer>
                </Tuple>
    ...
    </Result>
Run Code Online (Sandbox Code Playgroud)

xml powershell

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

如何修改%username%\AppData中的文件

我正在尝试使用 Powershell 修改 %appdata%\LocalLow\Sun\Java\Deployment 中的文件。脚本很简单:

Add-Content "%appdata%\LocalLow\Sun\Java\Deployment\deployment.properties" "mydata"
Run Code Online (Sandbox Code Playgroud)

但是,它返回“无法找到部分路径 'C:\Users\MyUsername\Desktop\%appdata%\LocalLow\Sun\Java\Deployment\deployment.properties”

即使我指定了 %appdata%,它也会添加到脚本的当前目录中。如何指定 C:\Users\MyUsername\%AppData% 文件夹?

powershell

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

PowerShell - 将扩展参数传递给 Start-Job cmdlet

我们尝试创建一个包含变量的数组,然后将该数组作为扩展传递给脚本,该脚本将由 Start-Job 运行。但实际上却失败了,我们也找不到原因。也许有人可以帮忙!?

$arguments= @()
$arguments+= ("-Name", '$config.Name')
$arguments+= ("-Account", '$config.Account')
$arguments+= ("-Location", '$config.Location')

#do some nasty things with $config

Start-Job -ScriptBlock ([scriptblock]::create("& .'$ScriptPath' [string]$arguments")) -Name "Test"
Run Code Online (Sandbox Code Playgroud)

它失败了

Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [Select-AzureSubscription], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.WindowsAzure.Commands.Profile.SelectAzureSubscriptionCommand
    + PSComputerName        : localhost
Run Code Online (Sandbox Code Playgroud)

即使 $config.name 设置正确。

有任何想法吗?

先感谢您!

arrays powershell start-job

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