小编nar*_*992的帖子

Powershell中字符串的颜色部分

我正在尝试只对整个行涂上“ None Provided”字符串。

到目前为止,我有:

$owned | % {write-host "Managing Group: " + ("None Found" -foreground red) "Group Description: None Provided"}
Run Code Online (Sandbox Code Playgroud)

问题在于()中的-foreground,“ f”显示为灰色,这会导致错误。它不带()就起作用(通过对整个行着色)。您能帮我给“未找到”上色吗?

通过使用Overflowed的答案,它帮助我解决了这一问题。谢谢!

编辑:

if ($owned -eq $Null){
$owned | % {write-host "Managing Group: " -nonewline}
$owned | % {write-host "None Found " -foreground red -nonewline}
$owned | % {write-host "Group Description: " -nonewline}
$owned | % {write-host "None Provided " -foreground red}
}

elseif ($description -eq $Null){
$owned | % {write-host "Managing Group: "($_.name) "Group Description: " -nonewline}
$owned …
Run Code Online (Sandbox Code Playgroud)

colors foreground

1
推荐指数
2
解决办法
5333
查看次数

Powershell:计算AD组的成员

接受了一个例子我可以使用和更正的代码

我目前的问题是如何计算组中的成员数量而不是打印出组中的所有成员(包括其ID名称或PC名称).注释掉的代码打印每个成员.我只想数数.

我在foreach循环中尝试了$ members.count,$ member.count和$ string.count但没有打印出来.请帮忙

Import-Module ActiveDirectory

$pathEmpty = "C:\Temp\groupsEmpty.txt"

Clear-Content $pathEmpty

$Header = `
"Group ID Name" + "|" + `
"Display Name" + "|" + `
"Description" + "|" + `
"Members"


#Write out the header
$Header | Out-File $pathEmpty -Append


$emptys = get-adgroup -properties name, displayname, description, members -filter  name -like "WA*" -or name -like "workstation*"} `
 | Select name, displayname, description, members

foreach ($empty in $emptys)
{
#clears previous 
$members = ""
foreach ($member in …
Run Code Online (Sandbox Code Playgroud)

powershell count

-2
推荐指数
3
解决办法
7万
查看次数

标签 统计

colors ×1

count ×1

foreground ×1

powershell ×1