小编rob*_*bdy的帖子

将安全字符串转换为纯文本

我正在使用power shell,我有成功将用户输入的密码转换为纯文本的代码:

$SecurePassword = Read-Host -AsSecureString  "Enter password" | convertfrom-securestring | out-file C:\Users\tmarsh\Documents\securePassword.txt
Run Code Online (Sandbox Code Playgroud)

我已经尝试了几种方法将其转换回来,但它们似乎都没有正常工作.最近,我尝试过以下内容:

$PlainPassword = Get-Content C:\Users\tmarsh\Documents\securePassword.txt

#convert the SecureString object to plain text using PtrToString and SecureStringToBSTR
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($PlainPassword)
$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR) #this is an important step to keep things secure
Run Code Online (Sandbox Code Playgroud)

这也给我一个错误.

Cannot convert argument "s", with value: "01000000d08c9ddf0115d1118c7a00c04fc297eb0100000026a5b6067d53fd43801a9ef3f8ef9e43000000000200000000000366000
0c0000000100000008118fdea02bfb57d0dda41f9748a05f10000000004800000a000000010000000c50f5093f3b87fbf9ee57cbd17267e0a10000000833d1d712cef01497872a3457bc8
bc271400000038c731cb8c47219399e4265515e9569438d8e8ed", for "SecureStringToBSTR" to type "System.Security.SecureString": "Cannot convert the "01000000
d08c9ddf0115d1118c7a00c04fc297eb0100000026a5b6067d53fd43801a9ef3f8ef9e430000000002000000000003660000c0000000100000008118fdea02bfb57d0dda41f9748a05f10
000000004800000a000000010000000c50f5093f3b87fbf9ee57cbd17267e0a10000000833d1d712cef01497872a3457bc8bc271400000038c731cb8c47219399e4265515e9569438d8e8
ed" value of type "System.String" to type "System.Security.SecureString"."
At C:\Users\tmarsh\Documents\Scripts\Local Admin Script\PlainTextConverter1.ps1:14 char:1
+ …
Run Code Online (Sandbox Code Playgroud)

powershell securestring

64
推荐指数
4
解决办法
8万
查看次数

如何在Powershell中获取错误行号

我正在尝试在运行Powershell脚本时获取错误的行号.这是我现在正在使用的内容:

$e = $_.Exception
$line = $_.Exception.InvocationInfo.ScriptLineNumber
$msg = $e.Message 

Write-Host -ForegroundColor Red "caught exception: $e at $line"
Run Code Online (Sandbox Code Playgroud)

有时候这种方法有效,有时则无效.我想知道我做错了什么,或者我能做些什么来使这项工作更加一致.

windows powershell

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

Git如何使用远程仓库的`set-url`

我需要更改远程存储库的 url,所以我正在查看https://git-scm.com/docs/git-remote上的文档,但是当我这样做时:

git remote set-url git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)

我收到消息 usage: git remote set-url [--push] <name> <newurl> [<oldurl>]

我不太明白,我应该输入:

git remote set-url --push gitusername git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)

或者代表什么<name>?我应该包括旧网址吗?

更新

所以当我输入:

git remote set-url --push origin git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)

在那种类型之后 git remote -v

我明白了:

origin  git@github.com:oldusername/oldrepo.git (fetch)
origin  git@github.com:gitusername/repository.git (push)
Run Code Online (Sandbox Code Playgroud)

如何更改提取?

git

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

如何为PowerShell安装GroupPolicy模块?

我刚刚开始在 PowerShell 中编写脚本。
所需的脚本应该创建一个本地 GroupPolicyObject (GPO),稍后将指定该对象。研究表明,可以使用New-GPOPowerShell 的 GroupPolicy 模块中的命令来完成此操作。我尝试安装上述模块,但不幸的是我发现没有任何效果。我可以寻求帮助吗?

我使用的是 Windows 7 和 Powershell 5.1.14409.1005

从 Microsoft 页面 ( ) 运行示例时收到错误New-GPO -Name TestGPO -Comment "This is a test GPO."运行时出错 (New-GPO -Name TestGPO -Comment "This is a test GPO.") - Microsoft 提供的示例

powershell module group-policy windows-7 gpo

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

使用应用程序将消息发布到 Microsoft Teams 频道

我正在尝试使用 Graph REST API(从我的应用程序)将消息发布到特定的 Microsoft Teams 频道。我正在查看以下 API 端点,但它说它不支持Application权限类型:在通道中创建 chatMessage

有没有比使用 webhook/bots 更好的方法?

microsoft-teams microsoft-graph-api

5
推荐指数
1
解决办法
3335
查看次数

使用 Powershell 关闭特定 Excel 文件

用于终止特定 Excel 文件的适当 PowerShell cmdlet 是什么?命令

Stop-Process -Name "excel"
Run Code Online (Sandbox Code Playgroud)

关闭所有打开的 Excel 应用程序。

提前致谢!

powershell

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

你能从ps1文件中加载ps1文件吗?

我可以从ps1文件中加载ps1文件吗?

最终目标是制作一个ps1文件,我放在我的配置文件中放在我的所有计算机上,并且有一个浮动配置文件,我可以把路径放到口袋实用程序中.我可能会将它放在代码仓库或一些外部共享机制中.

powershell

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

无法替换字符串中的“ $”

我想从PowerShell中的字符串替换“ $”。我正在尝试:

PS> $vars
abcd$
PS> $vars -replace "`$"
abcd$
Run Code Online (Sandbox Code Playgroud)

如何替换字符串中的“ $”?

powershell

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

想从 C++ 程序中运行 PowerShell 代码

我希望能够从我的 C++ 程序中运行 30 行 PowerShell 脚本。我听说这是一个糟糕的主意,我不在乎。我还是想知道怎么做。

我只想直接在 C++ 程序中编码,我不想从外部调用 PowerShell 脚本。有没有办法做到这一点?如果不可能,就说不。

例如

void runPScode() {

//command to tell compiler the following is PowerShell code
//a bunch of PowerShell code

}
Run Code Online (Sandbox Code Playgroud)

谢谢!

我一直在寻找执行此操作的命令并阅读了几个“类似”的问题。

c++ powershell

0
推荐指数
1
解决办法
2627
查看次数

从 PS 中的输出文件中排除扩展名?

C:\test我的目标是在名为 的日志文件中显示目录中的项目log.txt,而不显示找到的文件的文件扩展名,例如.zip.pdf等。

到目前为止我的脚本:

Get-ChildItem -Path C:\Test\ -name |Out-File C:\test2\log.txt
Run Code Online (Sandbox Code Playgroud)

如何使.log文件不显示文件夹中找到的文件的扩展名C:\test

powershell

0
推荐指数
1
解决办法
110
查看次数