我正在通过 Powershell 使用 Microsoft Team Foundation Server。我想要做的任务是为“测试用例”类型的给定工作项获取和设置“步骤”。
出于某种我不知道的原因,TFS 将诸如HTML 之类的信息存储在 XML 中,其中 HTML 元素是使用HTML 实体编写的,以免与 XML 混淆。
下面是一个例子:
<steps id="0" last="3">
<step id="2" type="ValidateStep">
<parameterizedString isformatted="true">
<DIV><P>I do this and that</P></DIV>
</parameterizedString>
<parameterizedString isformatted="true">
<DIV><P>&nbsp;</P></DIV>
</parameterizedString>
<description/>
</step>
<step id="3" type="ActionStep">
<parameterizedString isformatted="true">
<DIV><DIV><P>I do something else <BR/></P></DIV></DIV>
</parameterizedString>
<parameterizedString isformatted="true">
<DIV><P>This happens <BR/></P></DIV>
</parameterizedString>
<description/>
</step>
</steps>
Run Code Online (Sandbox Code Playgroud)
显示为:

如何获得每个项目的“裸文本”?例如,This happens出于<DIV><P>This happens <BR/></P></DIV>. 我必须编写自己的解析器还是已经有一些可以使用的东西?
我正在解析 Windows 系统 ($system) 的所有登录信息。我正在尝试获取域、用户、会话 ID 的元组/数组。
$logged_on_users = Get-WmiObject Win32_LoggedOnUser -ComputerName $system
Run Code Online (Sandbox Code Playgroud)
然后我调用类型的函数来提取每个值中的两个变量(Antecedent 和 Depedent):
$all_user_sessions = @()
foreach ($x in $logged_on_users){
$t = @()
$t += $x.GetPropertyValue("Antecedent").tostring()
$t += $x.GetPropertyValue("Dependent").tostring()
$all_user_sessions += $t
}
Run Code Online (Sandbox Code Playgroud)
单行数组理解的语法是什么(如果可能的话)?我有:
$all_user_sessions = ($logged_on_users | % { @($_.GetPropertyValue("Antecedent").tostring(), $_.GetPropertyValue("Dependent").tostring() ) })
Run Code Online (Sandbox Code Playgroud)
当我添加
foreach ($s in $all_user_sessions){
echo $s.GetType().FullName
}
Run Code Online (Sandbox Code Playgroud)
类型是字符串,而不是数组。
我正在使用Format-Table编写一个在列中发出输出的脚本,并且不能显示超过 9 个(无论有没有-AutoSize参数)。
以防万一这不是我的错,只是一些未记录的事情:
Format-Table可以显示的最大列数是多少?
如果它未绑定,我将从我的脚本中提取一个小的可重现案例。
我正在使用 PowerShell 4.0,并创建要列出的对象,如下所示:
New-Object PSCustomObject -Property ([Ordered] @{
"BDS #" = $bdsVersion
"HKCU" = $hkcuBasePath
"HKLM" = $hklmBasePath
"Name" = $fullName
"CompilerVersion" = $compilerVersion
"RTLVersion" = $rtlVersion
"Define" = $define
"Characterset" = $characterSet
"Architectures" = $architecture
"Frameworks" = $framework
"DllSuffix" = $dllSuffix
})
Run Code Online (Sandbox Code Playgroud)
DllSuffix即使我的控制台窗口足够宽(300 个字符宽),该列也不会显示。
编辑:
按照建议由Cole9350,我加入了-Wrap该-AutoSize参数来设置表的格式,但它仍然失败:
function Get-BDS-ProductSummaries {
$bdsVersions = Get-BDS-Versions
$bdsVersions | ForEach-Object {
$summary …Run Code Online (Sandbox Code Playgroud) 我有两个数组,我想比较它们的项目
我有数组 A [hi,no,lo,yes,because] 和数组 B [mick,tickle,fickle,pickle,ni,hi,no,lo,yes,because]
所以我想搜索 A 中的每个项目并与 B 中的每个项目进行比较,如果有匹配返回“有匹配”
给定一组键值对(例如通过 ConvertFrom-StringData 读入),是否有一种简化的方法可以将其转换为 Hashtable 或类似的以允许快速查找?即一种不需要我遍历数组并自己手动构建哈希表的方法。
示例数据
10.0.0.1=alice.example.com
10.0.0.2=bob.example.com
Run Code Online (Sandbox Code Playgroud)
示例用法
$names = gc .\data.txt | ConvertFrom-StringData
// $names is now Object[]
$map = ?
// $map should now be Hashtable or equivalent
echo $map['10.0.0.2']
// Output should be bob.example.com
Run Code Online (Sandbox Code Playgroud)
基本上我正在寻找的是一个,最好是内置的文件到哈希表的函数。或者一个数组到哈希表的函数。
注意:正如@mjolnior 所解释的,我实际上得到了哈希表,但是一个单值数组。所以这是通过读取文件来解决的-raw,因此不需要任何数组到哈希表的转换。更新了问题标题以匹配它。
我有一个带有两个值的字节数组:07和DE(十六进制)。
我需要做的是以某种方式连接07DE并从该十六进制值中获取十进制值。在这种情况下,它是2014。
我的代码:
# This line gives 11 bytes worth of information
[Byte[]] $hexbyte2 = $obj.OIDValueB
# All I need are the first two bytes (the values in this case are 07 and DE in HEX)
[Byte[]] $year = $hexbyte2[0], $hexbyte2[1]
Run Code Online (Sandbox Code Playgroud)
我如何组合这些来制作07DE并将其转换为 int 以获取2014?
我有一个文件夹,.doc我想将其转换为.txt格式。如何在 Windows 7 中使用 LibreOffice 的命令行模式来做到这一点?这些文件位于C:\Temp\Test.
我发现与 ScheduledTask cmdles 相关的错误给出了极其神秘的错误。我想安排一个测试任务每 1 分钟运行一次并永远重复。这是我正在尝试的,但没有成功:
cls
#$Action = New-ScheduledTaskAction -Execute "e:\Scripts\TestClusteredTask.cmd"
$DurationTimeSpan = New-TimeSpan -Minutes 1
$DurationTimeSpanIndefinite = ([TimeSpan]::MaxValue)
$DurationTempTest = New-TimeSpan -Days 1000
$Trigger = New-ScheduledTaskTrigger -Daily -At "00:01" -RepetitionInterval $DurationTimeSpan -RepetitionDuration $DurationTempTest
Run Code Online (Sandbox Code Playgroud)
也试过这个:
$Trigger = New-ScheduledTaskTrigger -Daily -At "00:01" -RepetitionInterval $DurationTimeSpan -RepeatIndefinitely
Run Code Online (Sandbox Code Playgroud)
错误输出:
New-ScheduledTaskTrigger : Parameter set cannot be resolved using the specified named parameters.
At C:\Users\nwalters\Documents\AddTestClusteredTask.ps1:6 char:12
+ $Trigger = New-ScheduledTaskTrigger -Daily -At "00:01" -RepetitionInterval $Dura ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-ScheduledTaskTrigger], ParameterBindingException …Run Code Online (Sandbox Code Playgroud) 查询两个日期的最明智的方法是什么。首选 PowerShell 或 Windows Batch 解决方案。我想要一个关于该主题描述的列表:
文件名、创建日期、最后修改时间
我知道:Dir 有 /t:[A,W,C] 但找不到一次显示多个日期的方法。对于文件有 @fdate @ftime 只查询修改日期。
我有以下程序(print-args.exe):
#include <iostream>
int main(int argc, char** argv)
{
for( int i = 1; i < argc; ++i )
{
std::cout << "Arg " << i << ": " << argv[i] << std::endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在某些情况下,带有点 (.) 的参数被分成两个参数:
PS C:\print-args> .\print-args.exe -text.txt /text.txt -path=c:\text.txt --foo=value.txt
Arg 1: -text
Arg 2: .txt
Arg 3: /text.txt
Arg 4: -path=c:\text.txt
Arg 5: --foo=value.txt
Run Code Online (Sandbox Code Playgroud)
从 cmd.exe 运行时,参数如预期:
C:\print-args>.\print-args.exe -text.txt /text.txt -path=c:\text.txt --foo=value.txt
Arg 1: -text.txt
Arg 2: /text.txt
Arg 3: -path=c:\text.txt
Arg …Run Code Online (Sandbox Code Playgroud) powershell ×10
arrays ×2
windows ×2
batch-file ×1
byte ×1
date ×1
doc ×1
eventtrigger ×1
hashmap ×1
hashtable ×1
html ×1
libreoffice ×1
tfs ×1
xml ×1