Good morning folks,
I have this script and I have a few questions.
1st is - Looking at the output, the last line of code Write-Host…it always prints before the end of the Get-ChildItem finishes, Ive tried a few things to get it to print it at the very end. I tried putting the Get-ChildItem inside a Start-Job scriptblock but that didnt work as expected. Its a minor thing but driving me crazy. Here is the script:
$ComputerName = Read-Host -Prompt "Please enter remote computer to query"
(Get-ADComputer "$ComputerName" -Properties *).DistinguishedName.Split(',')
$CurrentOU = (Get-ADComputer "$ComputerName" -Properties *).DistinguishedName.Split(',')
$features = Invoke-Command -ComputerName $Computername -ScriptBlock {
Date
Systeminfo
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform' -Name BackupProductKeyDefault |
Select-Object -Property BackupProductKeyDefault
Get-WmiObject -Class Win32_Processor
Get-CimInstance -ClassName Win32_BIOS
Get-CimInstance -ClassName Win32_ComputerSystem
Get-CimInstance -ClassName Win32_OperatingSystem | select LastBootUpTime
Get-WindowsFeature | Where-Object Installed | Format-Table Name, DisplayName, InstallState
Get-ChildItem -Path "C:\Temp" -Recurse
}
$features
$features | Out-File -FilePath "C:\Temp\ITScript\QueryRemote\QueryRemoteLogs\$ComputerName-Info.txt"
Add-Content -Path C:\Temp\ITScript\QueryRemote\QueryRemoteLogs\$ComputerName-Info.txt -Value $CurrentOU
Invoke-Item C:\Temp\ITScript\QueryRemote\QueryRemoteLogs\
Write-Host "Check log at C:\Temp\ITScript\QueryRemote\QueryRemoteLogs\$ComputerName-Info.txt for details" -ForegroundColor Yellow
The other question I have is regarding the 2nd and 3rd lines of code from the top of the script. The first is meant to print out the OU on screen, the second line is meant to stick that in a variable so I can add it to the log file at the end. Is there a way to do those 2 things without repeating the line of code, just 1 liner?
Thanks for all the help!