小编dca*_*caz的帖子

如何扩展变量中的属性

如果我走

$c = Resolve-DnsName facebook.com -Type TXT -Server '8.8.8.8'
Run Code Online (Sandbox Code Playgroud)

当我进入时$c我得到

Name                                     Type   TTL   Section    Strings
----                                     ----   ---   -------    -------
facebook.com                             TXT    7200  Answer     {v=spf1 redirect=_spf.facebook.com}        
facebook.com                             TXT    7200  Answer     {google-site-verification=A2WZWCNQHrGV_TW  
                                                                 wKh6KHY90tY0SHZo_RnyMJoDaG0s}
facebook.com                             TXT    7200  Answer     {google-site-verification=wdH5DTJTc9AYNwV  
                                                                 unSVFeK0hYDGUIEOGb-RReU6pJlY}
Run Code Online (Sandbox Code Playgroud)

我该如何扩展$c.strings

我知道我可以得到扩展的字符串并失去其余的

Resolve-DnsName facebook.com -Type TXT -Server '8.8.8.8' | Select-Object -ExpandProperty strings
Run Code Online (Sandbox Code Playgroud)

如何扩展整个答案?

powershell

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

启动进程、调用命令还是?

使用该程序可以得到您的支持或 GYB。我运行以下命令

Start-Process -FilePath 'C:\Gyb\gyb.exe' -ArgumentList @("--email <Email Address>", "--action backup", "--local-folder $GYBfolder", "--service-account", "--batch-size 4") -Wait
Run Code Online (Sandbox Code Playgroud)

问题是,当该过程完成时,我的脚本未完成。

$GYBfolder = $GYBfolder.Replace('"', "")
$output = [PSCustomObject]@{
    Name   = $SourceGYB
    Folder = $GYBfolder
}

$filename = "C:\reports\" + $SourceGYB.Split("@")[0] + "_Backup.csv"

$output | Export-Csv $filename -NoTypeInformation | Format-Table text-align=left -AutoSize
Return $filename
Run Code Online (Sandbox Code Playgroud)

由于某种原因,脚本在返回之前停止。我很想知道我是否应该使用不同的命令来运行 GYB?关于为什么脚本不处理返回的任何想法?

powershell

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

Try / Catch 或 Error 变量并使用

我想知道Try / Catch下面的方法是否有效,或者我应该使用 anIF ($problem)代替Try/Catch

Try {
    New-Item -Path C:\reports -ItemType Directory -ErrorAction SilentlyContinue -ErrorVariable Problem -Force
}
Catch {
    Write-Warning "Problem with C:\Report directory. Unable to create report $Type of $SourceEmail $Flag $DestinationEmail"
}
Run Code Online (Sandbox Code Playgroud)

我正在检查目录是否存在,如果不存在则尝试创建该目录。我不确定是否因为我正在使用-ErrorAction SilentlyContinue -ErrorVariable Problemtry/catch无法按预期工作?

替代方案

 New-Item -Path C:\reports -ItemType Directory -ErrorAction SilentlyContinue -ErrorVariable Problem -Force
 If ($Problem) {
  Write-Warning "Problem trying to create C:\Reports."
 }
Run Code Online (Sandbox Code Playgroud)

powershell

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

我如何在 Powershell 中运行它?

这是在命令提示符下工作的命令。

C:\Temp\Agent.exe CustomerId={9c0-4ab1-123-102423a} ActivationId={9c0-4ab1-123-102423a} WebServiceUri=https://Agent/
Run Code Online (Sandbox Code Playgroud)

这是错误。(我尝试过调用命令和参数,但我认为 { 引起了问题。

错误:Agent.exe:已指定命令参数。

powershell

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

找出两个非常大的列表中的不同之处

我有两个列表,每个列表大约有 1k 人。我要做的就是找出两者之间剩下的是谁。

$BunchoEmail = Import-Csv C:\temp\Directory.csv | Select-Object primaryEmail -ExpandProperty primaryEmail

$GoogleUsers = gam print users fields suspended | ConvertFrom-Csv | Where-Object suspended -ne $true | Select-Object primaryEmail -ExpandProperty primaryEmail

$objects = @{
    ReferenceObject  = $GoogleUsers
    DifferenceObject = $BunchoEmail
}
Compare-Object @objects
Run Code Online (Sandbox Code Playgroud)

以上没有产生我想要的。

找到不同之处的最佳方法是什么?

powershell set-difference compareobject

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

标签 统计

powershell ×5

compareobject ×1

set-difference ×1