出力に問題があります。出力に改行や改行が含まれないようにする別の方法をもう一度見てみたいと思いました。
誰か私を見てくれませんか?
$objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=Workstations");
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher;
$objSearcher.SearchRoot = $objDomain;
$objSearcher.PageSize = 100000;
$objSearcher.SearchScope = "Subtree";
$dateMonth = Get-Date -Format "MM";
$dateDay = Get-Date -Format "dd";
$dateYear = Get-Date -Format "yyyy";
$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll();
foreach ($objResult in $colResults)
{
$objItem = $objResult.Properties;
$computer = $objItem.name | Select-String -Pattern 'NSC';
Write-Host $computer;
#Add-Content "C:\PowerShell\Reports\Computer Report - $dateMonth-$dateDay-$dateYear.csv" "$computer";
}
出力例:
NSCNPR02
NSCNPR05
NSCNPR01
NSCNPR03
期待される出力:
NSCNPR03
NSCNPR05
NSCNPR01
NSCNPR03