Windows 如果他们有Skype for Business应用程序,请确定给定的计算机域

Windows 如果他们有Skype for Business应用程序,请确定给定的计算机域,windows,powershell,scripting,Windows,Powershell,Scripting,我需要您对我的PowerShell脚本的帮助和建议,已经有了在终端屏幕上显示它的初始程序,我的问题是我想将终端屏幕的输出导出到CSV文件 在computername.txt文件中: d-pol-abanaga d-pol-pcspc d-pol-eplete 守则: # Read input file of computer names $computers = Get-Content C:\pstool\computername.txt # Loop through each computer

我需要您对我的PowerShell脚本的帮助和建议,已经有了在终端屏幕上显示它的初始程序,我的问题是我想将终端屏幕的输出导出到CSV文件

computername.txt文件中:

d-pol-abanaga d-pol-pcspc d-pol-eplete 守则:

# Read input file of computer names
$computers = Get-Content C:\pstool\computername.txt
# Loop through each computer name in the array
foreach ($computer in $computers) {
    # Test for lync.exe file
    $path = Test-Path "<\\$computer\c$\program files\microsoft office\office15\*>" -Include lync.exe
    # Report if templates are found or not
    if ($path -eq $true) {
        Write-Output $Computer 'Skype for Business are present' |
            Export-Csv -Path "output.csv" -NoTypeInformation -Append
    } else {
        if ($path -eq $false) {
            $path16 = Test-Path "<\\$computer\c$\program files\microsoft office\office16\*>" -Include lync.exe
        }
    }

    if ($path16 -eq $true) {
        Write-Output $Computer 'Skype for Business are present' |
            Export-Csv -Path "output.csv" -NoTypeInformation -Append
    } else {
        Write-Output $Computer ' No Skype for Business are present' |
            Export-Csv -Path "output.csv" -NoTypeInformation -Append
    }
}
#读取计算机名称的输入文件
$computers=获取内容C:\pstool\computername.txt
#循环遍历数组中的每台计算机名称
foreach($computers in$computers){
#lync.exe文件的测试
$path=测试路径“”-包含lync.exe
#报告是否找到模板
if($path-eq$true){
写入输出$Computer“Skype for Business存在”|
导出Csv-路径“output.Csv”-NoTypeInformation-追加
}否则{
如果($path-eq$false){
$path16=测试路径“”-包括lync.exe
}
}
如果($path16-eq$true){
写入输出$Computer“Skype for Business存在”|
导出Csv-路径“output.Csv”-NoTypeInformation-追加
}否则{
写入输出$Computer“不存在Skype for Business”|
导出Csv-路径“output.Csv”-NoTypeInformation-追加
}
}

在您的问题中看不到您如何尝试导出CSV,这将是最有趣的部分

从此处复制了导出零件:


我认为在你感兴趣的Office版本上循环,并在其中一个版本中找到Skype后立即打破循环会容易得多。接下来,使用所需信息创建一个对象,并将其收集到变量
$result

大概是这样的:

# Loop through each computer name in the array from file 'C:\pstool\computername.txt'
# collect the data for export in variable $result
$result = foreach ($computer in (Get-Content 'C:\pstool\computername.txt')) {
    # Test for lync.exe file in Office versions 15 and 16
    $skype = 'Not present'
    for ($v = 15; $v -lt 17; $v++) {
        if (Test-Path -Path "\\$computer\c$\program files\microsoft office\office$v\*" -Include lync.exe) {
            $skype = 'Present'
            break
        }
    }

    # emit a PSObject to collect in the $result variable
    [PsCustomObject]@{
        'Computer'           = $computer
        'Skype for Business' = $skype
    }
}

# output to console
$result

# write results to CSV
$result | Export-Csv -Path "D:\output.csv" -NoTypeInformation -Append

从路径中删除角括号。此外,运行脚本的用户在远程计算机上是否具有管理员权限?否则,他们无法访问管理共享(
\\$computer\C$
)。谢谢,但我这里的问题是,当导出到CSV时,它有空数据,没有复制CSV文件中的确切输出:(那么请提出您的问题并出示a。当您的问题不允许我们理解或再现您面临的问题时,我们无法帮助您。@AnsgarWiechers已经编辑,如果我的问题有太多花哨的东西,我深表歉意。我不得不多次表达。请务必理解我。谢谢您,这取决于您想要导出什么。您可以向我们道歉。)e
Export Csv-Append
在循环内,但不能将
Write Host
输出导出到文件,因为该输出直接进入主机控制台。如果希望通过管道或重定向处理输出,请使用
Write output
而不是
Write Host
# Read input file of computer names
$computers = Get-Content C:\pstool\computername.txt
# Loop through each computer name in the array
foreach ($computer in $computers) {
    # Test for lync.exe file
    $path = Test-Path "<\\$computer\c$\program files\microsoft office\office15\*>" -Include lync.exe
    # Report if templates are found or not
    if ($path -eq $true) {
        Write-Output $Computer 'Skype for Business are present' |
            Export-Csv -Path "output.csv" -NoTypeInformation -Append
    } else {
        if ($path -eq $false) {
            $path16 = Test-Path "<\\$computer\c$\program files\microsoft office\office16\*>" -Include lync.exe
        }
    }

    if ($path16 -eq $true) {
        Write-Output $Computer 'Skype for Business are present' |
            Export-Csv -Path "output.csv" -NoTypeInformation -Append
    } else {
        Write-Output $Computer ' No Skype for Business are present' |
            Export-Csv -Path "output.csv" -NoTypeInformation -Append
    }
}
# Read input file of computer names
$computers = Get-Content C:\pstool\computername.txt
$Application = "lync.exe"
$results = @()
# Loop through each computer name in the array
foreach ($computer in $computers) {
    # Test for $Application file
    $path = Test-Path "\\$computer\c$\program files\microsoft office\office15\*" -Include $Application
    # Report if templates are found or not
    if ($path -eq $true ) {
        Write-Host $Computer 'Skype for Business are present'
    }
    else {
        if ($path -eq $false) {
            $path16 = Test-Path "\\$computer\c$\program files\microsoft office\office16\*" -Include $Application
        }
    }

    if ($path16 -eq $true) {
        $result = 'Skype for Business are present'
        Write-Host $Computer $result
        $details = @{      
            ComputerName = $Computer
            Result       = $result    
        }
    }
    else {
        $result = 'No Skype for Business are present'
        Write-Host $Computer $result
        $details = @{      
            ComputerName = $Computer
            Result       = $result
        }
    }
    $results += New-Object PSObject -Property $details  
}
$results | export-csv -Path c:\pstool\Check_for_lync.csv -NoTypeInformation
# Loop through each computer name in the array from file 'C:\pstool\computername.txt'
# collect the data for export in variable $result
$result = foreach ($computer in (Get-Content 'C:\pstool\computername.txt')) {
    # Test for lync.exe file in Office versions 15 and 16
    $skype = 'Not present'
    for ($v = 15; $v -lt 17; $v++) {
        if (Test-Path -Path "\\$computer\c$\program files\microsoft office\office$v\*" -Include lync.exe) {
            $skype = 'Present'
            break
        }
    }

    # emit a PSObject to collect in the $result variable
    [PsCustomObject]@{
        'Computer'           = $computer
        'Skype for Business' = $skype
    }
}

# output to console
$result

# write results to CSV
$result | Export-Csv -Path "D:\output.csv" -NoTypeInformation -Append