需要<ColourAddon>red</ColourAddon>在以下 xml 中的 GSIset 中添加此元素:
<?xml version="1.0" standalone="yes"?>
<GSIExplorer>
<GSISet>
<ID>local</ID>
<GSIServer>localhost</GSIServer>
<ALERT_TIMEOUT>30</ALERT_TIMEOUT>
</GSISet>
</GSIExplorer>
Run Code Online (Sandbox Code Playgroud)
我使用的代码是这样的:
[xml]$Xmlnew = Get-Content "C:\Program Files (x86)\GSI\gsiSettings\gsiPSSSettings2.xml"
$test = $Xmlnew.CreateElement("ColourAddon","red")
$Xmlnew.GSIExplorer.GSISet.AppendChild($test)
$Xmlnew.save("C:\Program Files (x86)\GSI\gsiSettings\gsiPSSSettings3.xml")
Run Code Online (Sandbox Code Playgroud)
我得到的结果是这样的
<?xml version="1.0" standalone="yes"?>
<GSIExplorer>
<GSISet>
<ID>local</ID>
<GSIServer>localhost</GSIServer>
<ALERT_TIMEOUT>30</ALERT_TIMEOUT>
<Colouraddon xmlns="asda" />
</GSISet>
</GSIExplorer>
Run Code Online (Sandbox Code Playgroud)
我想要这个:
<?xml version="1.0" standalone="yes"?>
<GSIExplorer>
<GSISet>
<ID>local</ID>
<GSIServer>localhost</GSIServer>
<ALERT_TIMEOUT>30</ALERT_TIMEOUT>
<ColourAddon>red</ColourAddon>
</GSISet>
</GSIExplorer>
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?
在我的 powershell 配置文件中,我有一个 的快捷方式docker ps,其格式设置是为了提高可读性
function dps {
docker ps --format "table {{.Names}}\t{{.ID}}\t{{.Status}}\t{{.Ports}}" | Sort-Object
# ????
# Tee-Object -Variable lines |
# select -first 1 |
# Write-Host;
# $lines | Sort-Object | Write-Host # Prints nothing
}
Run Code Online (Sandbox Code Playgroud)
以这种方式对行进行排序效果很好,并按名称对容器进行分组,但表头最终出现在输出的中间。
您可以看到我尝试分离出第一行输出(标题),但我不知道如何让表格继续打印。如何在排序和打印表格时将表格标题保持在顶部?
样本输出
database_A 27b33272e64c Up 15 hours 3306/tcp, 33060/tcp
database_B 1b1662223f17 Up 15 hours 33060/tcp, 0.0.0.0:33640->3306/tcp
database_C 8f98fc0890cc Up 15 hours 3306/tcp, 33060/tcp
framework_A a0d829729c8e Up 15 hours (unhealthy) 5050/tcp, 0.0.0.0:5170->80/tcp
NAMES CONTAINER ID STATUS PORTS
service_A …Run Code Online (Sandbox Code Playgroud) 我正在选择已安装应用程序的 DisplayName 和 DisplayVersion 属性,如下所示:
$response = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.DisplayName -like '*My Application*'} | Select-Object DisplayName, DisplayVersion | ft -HideTableHeaders
Run Code Online (Sandbox Code Playgroud)
结果是:My Application 1.2
为了额外的解析目的,我需要将结果与管道字符连接起来,以便它返回为:My Application|1.2
但是我无法找到正确的语法。
我正在使用 powershell 创建一个窗口任务,一切正常,但我找不到如何添加作者姓名。将ScheduledTask注册为描述的参数,但不适用于作者。
导出的 Windows 任务
<RegistrationInfo>
<Date>2016-05-17T16:45:54.3423362</Date>
<Author>NEED TO SET THIS</Author>
<URI>RunLauncherTask</URI>
</RegistrationInfo>
Run Code Online (Sandbox Code Playgroud)
ai 用于创建任务的代码
$principal = New-ScheduledTaskPrincipal -UserId (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -expand UserName)
$allTasks = Get-ScheduledTask | Select TaskName
$action = New-ScheduledTaskAction -Execute "C:\Launcher.exe"
$trigger = New-ScheduledTaskTrigger -AtLogOn
$task = New-ScheduledTask -Action $action -Trigger $trigger -Principal $principal
$username = $principal.UserId
$taskName = 'RunLauncherTask' + $username.Replace('\','-')
$settings = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries
Register-ScheduledTask $taskName -Action $action -Settings $settings
Run Code Online (Sandbox Code Playgroud)
如何设置作者?
运行命令bash或ubuntu在 PowerShell 中时,会输入 Windows-Subsystem-for-Linux,但是,PowerShell 的当前工作目录不会传递到 BASH。有没有办法实现这个功能?
我正在使用 PowerShell 获取 MX 记录数组。我想知道为什么以下命令会返回 SOA 记录,因为我已为类型参数指定了 MX。此外,SOA 记录有助于电子邮件传送吗?
Resolve-DnsName $SomeDomainName -type MX -Server 8.8.8.8 -DnsOnly -ErrorAction Stop
Run Code Online (Sandbox Code Playgroud) 我试图使一个变量等于一个范围。我的脚本包括用户输入,并且该输入必须落在某个范围内。我将在脚本中多次使用该范围,因此我希望它是一个变量。这是我尝试过的:
$serverrange = "1..18"
Run Code Online (Sandbox Code Playgroud)
我试过了
$serverrange = 1..18
Run Code Online (Sandbox Code Playgroud)
我已经用谷歌搜索过,但找不到太多关于此的信息。问题是 PowerShell 并不将其视为一个范围,而是将其视为字面上的 1..18。因此,如果我执行 Write-Output $serverrange,它会显示为“1..18”。所以我的问题是如何让它将其视为一个范围,或者如何更改脚本以合并该范围?这是脚本的其余部分:
#user input for how many servers will be tested
$numofservers = Read-Host -Prompt "How many servers are being tested?"
if($numofservers -eq $serverrange) {
"Proceed"
}
else {
"Server limit exceeded"
}
Run Code Online (Sandbox Code Playgroud)
编辑:没有意识到 $serverrange = 1..18 有效。
我尝试使用 Get-Children cmdlet 的 -Depth 参数来查找具有相同名称的 2 个文件中较浅(较浅)的文件,如下所示。
C:\temp\test.txt
C:\temp\Logs\test.txt
Run Code Online (Sandbox Code Playgroud)
许多帖子建议将 -Path 定义为“C:\temp\ ”或“C:\temp \\*”。但就我而言,我更喜欢使用 -Depth 参数来限制搜索中递归的深度。我读到它意味着递归,因此不需要与递归结合使用。到目前为止,我已经尝试了下面的所有命令,但它们都返回下面显示的相同结果。
Get-ChildItem -Path C:\temp -Depth 0 -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth 1 -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth 2 -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth 3 -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth '1' -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth "1" -Include tes*.txt | …Run Code Online (Sandbox Code Playgroud) 如何在 PowerShellswitch语句中添加条件?下面的代码在0应该返回时返回1000。
$UsedSpaceMB = 8500
switch ($UsedSpaceMB) {
($UsedSpaceMB -gt 15000) { $FreeSpace = 2000 }
($UsedSpaceMB -in 8000..15000 ) { $FreeSpace = 1000 }
($UsedSpaceMB -in 1700..8000 ) { $FreeSpace = 500 }
($UsedSpaceMB -in 1000..1700 ) { $FreeSpace = 200 }
($UsedSpaceMB -in 800..1000 ) { $FreeSpace = 100 }
($UsedSpaceMB -lt 800 ) { $FreeSpace = 50 }
}
$FreeSpace
Run Code Online (Sandbox Code Playgroud) 我有一个 PowerShell 脚本文件存储在内部工件服务器中。脚本网址为http://company-server/bootstrap.ps1.
下载该脚本并使用自定义参数执行的简洁方法是什么?
我想将这样的命令发送给用户,他们会一遍又一遍地复制粘贴它,因此它必须是单行并且应该很短。
我目前所做的工作,但它又长又笨拙:
$c=((New-Object System.Net.WebClient).DownloadString('http://company-server/bootstrap.ps1'));Invoke-Command -ScriptBlock ([Scriptblock]::Create($c)) -ArgumentList 'RunJob'
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更短的方法来做到这一点。