Questions tagged «powershell»

Windows PowerShell是Windows的命令行外壳程序和脚本语言,它取代了CMD.exe Shell和批处理语言。PowerShell还是Windows的自动化引擎,提供类似于Windows Script Host和VBScript的功能。

0
Bamboo Windows代理(Powershell / Batch)中BitBucket存储库的自动标记
我正在尝试自动化项目存储库的标记。该代码托管在私有的BitBucket上,而持续集成在Bamboo上自动进行,而Bamboo仅在当前Windows 10代理上运行。该代理具有MINGW GitPowerShell的功能,但是从Bamboo来说,我只能在cmd.exe或上设置命令行任务Windows PowerShell。 我已经在BitBucket上设置了一个特定用户,该用户具有对存储库的写权限以及已知的密码。用户通过SSH在BitBucket上进行身份验证: remote.origin.url=ssh://git@git.mycompany.com:7999/myproject/myrepository.git 该origin.url变量是直接从Bamboo变量设置的,因此没有简单的方法可以切换到https://username:password@git.mycompany.com...url以手动指定密码。 如果没有做任何事情比设置本地多user.name和user.password到适当值时,git push --tags命令失败: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 因此,我猜想授予用户访问权限的正确方法是使用SSH身份验证方法。但是,PowerShell中的Git实例似乎并不了解pageant:通过Git Bash导入ssh密钥后,该命令在PowerShell上仍然失败,但在Git Bash中成功。在这一点上,我陷入了困境,因为似乎无法让PowerShell知道我的id_rsa文件.pub或.ppk,并且尝试从PowerShell调用Git Bash以使其他可执行文件执行肮脏的工作失败了: "C:\Program Files\Git\git-bash.exe git push --tags --set-upstream origin test-tag-branch" "C:\Program Files\Git\bin\git.exe push --tags --set-upstream …




0
FileSystemWatcher不会由机器操作触发
我有这个脚本来监视文件夹中的新文件: $watcher = New-Object System.IO.FileSystemWatcher $watcher.Path = "C:\source" $watcher.Filter = "*.xml*" $watcher.IncludeSubdirectories = $true $watcher.EnableRaisingEvents = $true $action = { $path = $Event.SourceEventArgs.FullPath $xml = [xml](get-content $Path) $checkpoint = $xml.recognitionevent.checkpoint $licenseplate = $xml.recognitionevent.frontlicenseplates.licenseplate.formatted If ($licenseplate -eq 9224026) { If ($checkpoint -eq 1) { $write = "7" } ElseIf ($checkpoint -eq …

1
在powershell命令提示符下用其值替换变量
在Windows PowerShell中,是否有一种“评估”变量的方法,以便将其值粘贴到命令提示符下?我要执行的使用场景如下: 假设我有一个$path包含“ C:/ Users / Me / Some / Long / Path” 的变量。我想cd $path在命令提示符下写入内容,然后$path用其值替换,这样我就可以cd C:/Users/Me/Some/Long/Path在命令提示符下使用它并可以手动编辑长路径,并最终按Enter更改目录。是否存在这种或类似行为?仅使用变量,而不cd使用开头是否有可能?

1
如何在Windows Powershell中为gnuwin32工具创建自定义别名
我已经安装了gnuwin32并将其附加到我的环境中,因此在命令提示符下键入ls时,我会运行linux / unix“ ls”。显然,这对于Powershell而言不是问题,但是我无法创建具有相同名称(ls)或不同名称(lsa / ll / ld)的自定义别名,并且出现以下错误: The script failed due to call depth overflow. + CategoryInfo : InvalidOperation: (0:Int32) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : CallDepthOverflow 现在,这是我的Powershell脚本: Set-Alias -name ls -value ListDirectory -Option AllScope Function ListDirectory { $Command = "ls -I ntuser\.* -I NTUSER\.*"; Invoke-Expression $Command } 有任何想法吗?关于忽略文件,我需要它们。为了确保此命令在旧命令提示符下正常工作,我在Powershell中仅遇到了问题:(

0
如何使用Powershell正确安装Windows Store应用程序?
我试图使用PS命令安装Windows Store App: Add-AppxPackage -register "C:\Program Files\WindowsApps\Microsoft.WindowsStore_2015.9.9.0_x64__8wekyb3d8bbwe\AppxManifest.xml" -DisableDevelopmentMode 但失败了: PS C:\WINDOWS\system32> Add-AppxPackage -register "C:\Program Files\WindowsApps\Microsoft.WindowsStore_2015.9.9.0_x64 wekyb3d8bbwe\AppxManifest.xml" -DisableDevelopmentMode Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF6, Package could not be registered. Merge Failure : error 0x80070003 : Cannot register the Microsoft.WindowsStore_2015.9.9.0_x64__8wekyb3d8bbwe package because there was a merge failure with the following file: …



2
如何在Powershell中创建激活事件的Windows任务
嘿,我需要创建一个Windows任务,其行为很像组策略中的注销脚本(我们的环境没有AD)。该任务需要以登录用户身份运行,以便脚本可以将运行它的用户的名称输出到跟踪用户注销/登录时间和日期的.csv中。我不确定powershell是否是执行此操作的绝对最佳方式,但我需要能够以管理员身份创建任务,但将用户设置为以当前登录用户身份运行脚本,无论当时可能是谁。这将被部署到数百台机器上。 如果还有另一种跟踪用户注销的方法,那么无论是否涉及PowerShell,我都会对该方法非常感兴趣。以前我已经尝试通过编辑注册表来运行脚本以尝试在GP中设置Logoff脚本,但这似乎比我最初预期的更复杂。Zenworks是另一种选择,但它只在用户注销后运行脚本,导致脚本将错误的结果输出到.csv中。 作为参考,下面的链接包含有类似问题但没有我需要定位的某些细节的人。 https://stackoverflow.com/questions/33390035/windows-creating-a-task-for-an-event-from-the-command-line

1
FOR循环中的Windows批量powershell命令不起作用
我在批处理文件中有以下循环: for /l %%x in (1, 1, %k%) do ( set "psCommand=powershell -Command "$pword = read-host 'Enter Password2' -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)"" for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p ) 我总是得到以下错误: [System.Runtime.InteropServices.Marshal] :: PtrToStringAuto($ BSTR)“”此时出乎意料。 当我在for循环外运行命令时,它可以工作。 怎么了?


2
如何在Windows上流式传输到mpv时退出youtube-dl?
我经常使用命令mpv <YouTube URL> --no-video(FFmpeg也可能是必须的)仅在视频轨道冗余时传输音频,通常应节省超过99%的带宽。我在PowerShell中运行该命令,但尚未找到退出方法而不关闭并重新启动PowerShell - 热键Ctrl+ Z和Ctrl+ X导致[input] No key binding found for key...输出。

2
无法使用PowerShell安装ISO映像文件
PS F:\ISOs\System> [System.Environment]::OSVersion.Version Major Minor Build Revision ----- ----- ----- -------- 10 0 14393 0 PS F:\ISOs\System> dir Directory: F:\ISOs\System Mode LastWriteTime Length Name ---- ------------- ------ ---- ... -a---- 11/1/2013 13:32 134971392 Win7PE2.iso ... PS F:\ISOs\System> Mount-DiskImage -ImagePath .\Win7PE2.iso -Verbose Mount-DiskImage : The system cannot find the file specified. …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.