我正在使用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脚本时获取错误的行号.这是我现在正在使用的内容:
$e = $_.Exception
$line = $_.Exception.InvocationInfo.ScriptLineNumber
$msg = $e.Message
Write-Host -ForegroundColor Red "caught exception: $e at $line"
Run Code Online (Sandbox Code Playgroud)
有时候这种方法有效,有时则无效.我想知道我做错了什么,或者我能做些什么来使这项工作更加一致.
我需要更改远程存储库的 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)
如何更改提取?
我刚刚开始在 PowerShell 中编写脚本。
所需的脚本应该创建一个本地 GroupPolicyObject (GPO),稍后将指定该对象。研究表明,可以使用New-GPOPowerShell 的 GroupPolicy 模块中的命令来完成此操作。我尝试安装上述模块,但不幸的是我发现没有任何效果。我可以寻求帮助吗?
我使用的是 Windows 7 和 Powershell 5.1.14409.1005
从 Microsoft 页面 ( ) 运行示例时收到错误New-GPO -Name TestGPO -Comment "This is a test GPO.":

我正在尝试使用 Graph REST API(从我的应用程序)将消息发布到特定的 Microsoft Teams 频道。我正在查看以下 API 端点,但它说它不支持Application权限类型:在通道中创建 chatMessage
有没有比使用 webhook/bots 更好的方法?
用于终止特定 Excel 文件的适当 PowerShell cmdlet 是什么?命令
Stop-Process -Name "excel"
Run Code Online (Sandbox Code Playgroud)
关闭所有打开的 Excel 应用程序。
提前致谢!
我可以从ps1文件中加载ps1文件吗?
最终目标是制作一个ps1文件,我放在我的配置文件中放在我的所有计算机上,并且有一个浮动配置文件,我可以把路径放到口袋实用程序中.我可能会将它放在代码仓库或一些外部共享机制中.
我想从PowerShell中的字符串替换“ $”。我正在尝试:
PS> $vars
abcd$
PS> $vars -replace "`$"
abcd$
Run Code Online (Sandbox Code Playgroud)
如何替换字符串中的“ $”?
我希望能够从我的 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:\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 ×8
c++ ×1
git ×1
gpo ×1
group-policy ×1
module ×1
securestring ×1
windows ×1
windows-7 ×1