我在文本文件中有这个XML文档:
<?xml version="1.0"?>
<Objects>
<Object Type="System.Management.Automation.PSCustomObject">
<Property Name="DisplayName" Type="System.String">SQL Server (MSSQLSERVER)</Property>
<Property Name="ServiceState" Type="Microsoft.SqlServer.Management.Smo.Wmi.ServiceState">Running</Property>
</Object>
<Object Type="System.Management.Automation.PSCustomObject">
<Property Name="DisplayName" Type="System.String">SQL Server Agent (MSSQLSERVER)</Property>
<Property Name="ServiceState" Type="Microsoft.SqlServer.Management.Smo.Wmi.ServiceState">Stopped</Property>
</Object>
</Objects>
Run Code Online (Sandbox Code Playgroud)
我想迭代每个对象并找到DisplayName和ServiceState.我该怎么办?我尝试了各种组合,并努力解决这个问题.
我这样做是为了将XML转换为变量:
[xml]$priorServiceStates = Get-Content $serviceStatePath;
$serviceStatePath上面显示的xml文件名在哪里.然后我想我可以这样做:
foreach ($obj in $priorServiceStates.Objects.Object)
{
if($obj.ServiceState -eq "Running")
{
$obj.DisplayName;
}
}
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我希望输出一个字符串 SQL Server (MSSQLSERVER)
安装SQL 2016会自动打开所有"CEIP"或客户体验改善计划元素.这些元素向Microsoft报告安装体验的各个方面以及功能使用情况.我想把它关掉,因为无论如何它都被我们的防火墙阻挡了,我不需要头疼.
我正在开发一个C#WinForms应用程序.如果服务器上有可用的更新,则此应用程序可以更新.它工作正常,但仅适用于管理员用户.
如果用户没有管理员权限,应用程序将使用以下步骤检查并应用更新:
问题
应用更新后(仅适用于普通用户)应用程序以管理员用户身份运行,我正在尝试获取当前用户的Documents文件夹路径.它给了我admin用户的Documents文件夹路径,因为应用程序当前正以admin用户身份运行,但我想要当前登录用户的Documents文件夹路径.
题
如果应用程序以管理员用户身份运行,如何获取当前登录用户的Documents文件夹?
目前我使用下面的代码获取文档文件夹路径.
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Run Code Online (Sandbox Code Playgroud) 我在项目中添加了EPPlus和OfficeOpenXml的使用.但是,当我运行我的项目时,我收到此错误并发出警告:
警告 :
The referenced assembly "EPPlus" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.
Run Code Online (Sandbox Code Playgroud)
错误:
The type or namespace name 'OfficeOpenXml' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'ExcelPackage' could not be found (are you missing a …Run Code Online (Sandbox Code Playgroud) 由于某种原因,当将 PowerShell 中的某些值从十六进制转换为十进制时,我得到了不正确的值。
例如: - 输入0xC0000000然后按回车键,您会得到-1073741824不正确的值,正确的值为3221225472。给出的答案是我输入的负十六进制数的值FFFFFFFFC0000000
我认为这可能是一个解释问题,所以我明确要求将值从十六进制转换为 Base10(十进制),我仍然得到相同的错误答案-1073741824:
[Convert]::ToString(0xc0000000,10)
Run Code Online (Sandbox Code Playgroud)
为什么 PowerShell 将0xc0000000十六进制数解释为负数c0000000?我在这里错过了什么吗?
我有以下代码:
cls
Get-Module -ListAvailable | Import-Module
Import-Module ActiveDirectory
$Groups = Get-ADGroup -Filter {name -like 'XYZ'} | select name -
ExpandProperty name
$i=0
$tot = $Groups.count
$Table = @()
$Record = @{
"Group Name" = ""
"Name" = ""
"username" = ""
}
Foreach ($Group in $Groups) {
#// Set up progress bar
$i++
$status = "{0:N0}" -f ($i / $tot * 100)
Write-Progress -Activity "Exporting AD Groups" -status "Processing
Group $i of $tot : $status% Completed" -PercentComplete ($i / $tot …Run Code Online (Sandbox Code Playgroud)