标签: powershell

如何在Start-Transcript的输出中显示详细消息?

使用Start-Transcript详细输出时,不会在记录中捕获.例如:

Start-Transcript
Write-Verbose "This is a test of verbose output"
Stop-Transcript
Run Code Online (Sandbox Code Playgroud)

结果是:

**********************
Windows PowerShell transcript start
Start time: 20170829110436
Username: xx\xx
RunAs User: xx\xx
Machine: SGC340 (Microsoft Windows NT 6.1.7601 Service Pack 1)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 19596
PSVersion: 5.0.10586.117
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0.10586.117
BuildVersion: 10.0.10586.117
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\Users\xx\Documents\PowerShell_transcript.xx.EbGyj9PE.20170829110436.txt
PS C:\Users\xx> Write-Verbose "This is a test of verbose output"
PS C:\Users\xx> Stop-Transcript …
Run Code Online (Sandbox Code Playgroud)

powershell

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

使用PowerShell搜索AD而不使用AD模块(RSAT)

ActiveDirectory模块随附远程服务器管理工​​具(RSAT)。我想避免在PC客户端上安装RSAT。有没有一种方法可以不使用Active Directory模块来检索AD组的成员?

powershell active-directory

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

getfolderpath和程序数据

我已经成功地使用[environment]::getfolderpath("ProgramFiles"),以获得路径程序文件,但现在我有必要还可以访问程序数据,它看起来从这个枚举像ProgramData不可用此方法。是真的,还是我在这里想念东西?

powershell

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

为什么PowerShell无法发送适当的Crumb?

我的PowerShell脚本:

$Params = @{
    uri     = "http://${API_URL}:${API_Port}/crumbIssuer/api/json";
    Method  = 'Get';
    Headers = @{
        Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$(${API_User}):$(${API_Pass})"));
    }
}

$API_Crumb = Invoke-RestMethod @Params

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Jenkins-Crumb", $API_Crumb.Crumb)

$Params = @{
    uri     = "http://${API_URL}:${API_Port}/job/${API_Job}/build";
    Method  = 'Post';
    Headers = $headers;
}

Invoke-RestMethod @Params
Run Code Online (Sandbox Code Playgroud)

错误:

请求中未包含有效面包屑

powershell jenkins

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

为什么不直接使用powershell中的命令工作?

为什么以下工作:

Get-WmiObject -class Win32_OperatingSystem
Run Code Online (Sandbox Code Playgroud)

这也有效:

$params = @{class='Win32_OperatingSystem'}
Get-WmiObject @params
Run Code Online (Sandbox Code Playgroud)

但这不起作用:

Get-WmiObject @{class='Win32_OperatingSystem'}
Run Code Online (Sandbox Code Playgroud)

错误:

Get-WmiObject : Invalid query "select * from System.Collections.Hashtable"
At line:1 char:1
+ Get-WmiObject @{class='Win32_OperatingSystem'}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Run Code Online (Sandbox Code Playgroud)

powershell splat

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

Visual Studio Build Agent脚本安装

我正在尝试自动化VSTS Build Agent安装程序(https://www.visualstudio.com/en-us/docs/build/actions/agents/v2-windows)。

但是,此过程中有一个交互式步骤。这是一个cmd脚本文件,需要用户输入。我尝试使用设置生成一个TXT文件,然后运行脚本以读取该文件中的输入:

.\config < settings.txt
Run Code Online (Sandbox Code Playgroud)

但这没有用。我收到该消息:

Enter server URL > Enter authentication type (press enter for PAT) > Enter perso
nal access token > Cannot read keys when either application does not have a cons
ole or when console input has been redirected. Try Console.Read.
Run Code Online (Sandbox Code Playgroud)

是否可以通过脚本设置构建代理?有什么方法config.cmd可以完美地“重定向”控制台输入吗?

powershell windows-scripting azure-pipelines

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

如何永久更改PowerShell和CMD提示

PowerShell 可以通过调用来更改提示

Function prompt{"new_prompt "}
Run Code Online (Sandbox Code Playgroud)

并且cmd可以通过调用更改提示

prompt $g$g$s
Run Code Online (Sandbox Code Playgroud)

关闭当前窗口后,所有更改都将消失,并且在打开PowerShell或的新实例时,必须再次更改它们cmd.如何让这些变化永久化?

windows powershell cmd

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

无法删除变量,因为它已经过优化且无法移除 - 释放COM对象

在我的脚本结束时我使用'ie' | ForEach-Object {Remove-Variable $_ -Force}.它在PS 2(Windows 7)中工作正常,但PS 5(Windows 10)引发错误:

无法删除变量,即因为变量已经过优化且无法移除.尝试使用Remove-Variable cmdlet(不带任何别名),或者使用您正在使用的命令来删除变量.

怎样才能让它与PS 5搭配得更好; 或者我应该使用Remove-Variable 'ie' -Force?

com powershell

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

Powershell:在Windows 10中获取GPS坐标-使用Windows位置API?

我正在寻找一种使用Windows Location API从Powershell脚本收集内部GPS数据的方法,因为Windows Location Platform不再能够满足需求。以前,有一个com对象要使用。

在Windows 10中有没有办法做到这一点?

powershell gps geolocation windows-10 windows-locationapi

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

如何使用SSH和PowerShell中的私钥连接到Linux服务器?

我已经使用puttygen生成了一个ssh密钥对,并且可以使用Windows 10工作站上的putty的私钥成功连接到CentOS服务器:

成功连接到CentOS的图像

我想从Windows PowerShell连接到服务器,并使用以下命令加载了Posh-SSH模块: Install-Module posh-ssh

我尝试使用以下命令创建一个新的ssh会话:

$Credential = Get-Credential
$KeyFile = 'C:\Users\mark\Documents\ssh\privkey.ppk'
$sesh = New-SSHSession -ComputerName neon.localdomain -Credential $credential -Keyfile $KeyFile
Run Code Online (Sandbox Code Playgroud)

我输入了root和空白密码,Get-Credential但出现此错误:

New-SSHSession:无效的私钥文件。

我试图通过读取私钥文件并将其转换为以base64编码的方式将privkey文件转换为字符串,但出现相同的错误:

$privkeyString = Get-Content $KeyFile
$Bytes = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($privkeyString))
$sesh = New-SSHSession -ComputerName neon.localdomain -Credential $credential -KeyString $Bytes
Run Code Online (Sandbox Code Playgroud)

我也试过了,但是得到了同样的错误:

$sesh = New-SSHSession -ComputerName neon.localdomain -Credential $credential -KeyString $privkeystring
Run Code Online (Sandbox Code Playgroud)

关于如何使用带有私钥文件的PowerShell连接到linux服务器的任何想法?

ssh powershell powershell-5.0

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