小编lma*_*ave的帖子

Powershell-输出颜色以获得某些结果

我正在运行下面的代码,它可以工作。我想做的是,在Enabled属性为True的结果中,我希望文本'True'前景色为绿色,否则为'false'为红色。

与“密码永不过期”属性相同,如果结果为“ True”,我希望文本“ True”的前景色为红色,否则为“ False”的绿色。

我试图将if-else语句放入代码中,但没有成功。

码:

Get-ADUser "user name"  -Properties Enabled,LockedOut,DisplayName,GivenName, SurName,Mail,LastLogon, Created,passwordlastset,Passwordneverexpires,msDS-UserPasswordExpiryTimeComputed, Description, office, Canonicalname | `
        Select-Object Enabled, 
        @{Expression={$_.LockedOut};Label='Locked';}, 
        @{Expression={$_.DisplayName};Label='Display Name';},
        @{Expression ={$_.GivenName};Label='Name';}, `
        @{Expression ={$_.SurName}; Label='Last Name'; }, 
        Mail, 
        @{Expression ={[DateTime]::FromFileTime($_.LastLogon)}; Label='Last Logon';}, 
        @{Expression={$_.Created};Label='Date Created';}, 
        @{Expression={$_.passwordlastset};Label='PW Last Reset';}, 
        @{Expression={$_.Passwordneverexpires};Label='PW Never Expires';},
        @{Name="PW Exp Date";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}  ,
        Description, 
        Office,
        Canonicalname 
        Format-list
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

有什么建议么?

powershell

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

标签 统计

powershell ×1