0

考虑:

$ProfilePath = "HKLM:\software\microsoft\windows NT\currentversion\profilelist"
$ProfileList = ls -path $ProfilePath
foreach ($guid in $ProfileList)
{
    $gpath = $guid -replace "HKEY_LOCAL_MACHINE","HKLM:"
    $userpath = Get-ItemProperty -path "$gpath" | select ProfileImagePath
    $SUserName = [system.string]::$userpath
    $username = $userpath -replace "ProfileImagePath=C:\\Users\\",""
}

目前$userpath = @{ProfileImagePath=C:\Windows\ServiceProfiles\NetworkService. 我需要把它变成一个字符串,以便进行比较。我怎样才能让它转换为字符串?

我尝试$SUserName生成 ablanknull string.

4

3 回答 3

0

也许我不明白你的问题。

但我认为你正在寻找这个:

$userpath.ProfileImagePath
于 2012-05-09T20:30:30.297 回答
0

您可以使用以下命令将路径作为字符串获取:

$ProfilePath = "HKLM:\software\microsoft\windows NT\currentversion\profilelist\*"
Get-ItemProperty $ProfilePath | foreach {$_.ProfileImagePath}

或使用 split-path 仅提取用户名

Get-ItemProperty $ProfilePath | foreach {Split-Path $_.ProfileImagePath -Leaf}
于 2012-05-09T19:56:53.993 回答
0

尝试这个:

 $key = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\*'
 $key1 = (Get-ItemProperty -Path $key -Name ProfileImagePath).ProfileImagePath
于 2017-02-10T15:31:56.177 回答