I am trying to run the following command on multiple machines on a LAN (not on a domain). When I run without the Invoke-Command on the local machine it works perfectly. When I try to invoke, it can no longer find the file path on the machine I am running the command to as it is looking at the remote directory. I cannot get a sharedrive to function for this purpose. I had a similar question for which a hash table was suggested and successfully implemented. I cannot figure out how I would do that with the below.
Invoke-Command -Computername $computers -Credential {
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName,DisplayVersion,Publisher,InstallDate,InstallLocation | Format-Table -Property DisplayName,DisplayVersion,Publisher,InstallDate,InstallLocation -AutoSize | Out-File -Width 2048 "c:\scripts\ComputerInformation\SoftwareInformation\$env:COMPUTERNAME.software.txt"
$applications = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*
foreach ($application in $applications) {
$hostname = $env:COMPUTERNAME
$DisplayName = $application.DisplayName
$displayVersion = $application.DisplayVersion
$HelpLink = $application.HelpLink
$IdentifyingNumber = $application.PSChildName
$InstallDate = $application.InstallDate
$RegOwner = $null
$vendor = $application.Publisher
if ($DisplayName -ne $null -or $DisplayVersion -ne $null -or $HelpLink -ne $null -or $IdentifyingNumber -ne $null -or $InstallDate -ne $null -or $vendor -ne $null ) {
Add-Content -Path 'c:\scripts\Inventories\SoftwareInventory.csv' "$hostname,$DisplayName,$DisplayVersion,$HelpLink,$IdentifyingNumber,$InstallDate,$RegOwner,$Vendor"
}
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName,DisplayVersion,Publisher,InstallDate,InstallLocation | Format-Table -Property DisplayName,DisplayVersion,Publisher,InstallDate,InstallLocation -AutoSize | Out-File -Append -Width 2048 "c:\scripts\ComputerInformation\SoftwareInformation\$env:COMPUTERNAME.software.txt"
$applications = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*
foreach ($application in $applications) {
$hostname = $env:COMPUTERNAME
$DisplayName = $application.DisplayName
$displayVersion = $application.DisplayVersion
$HelpLink = $application.HelpLink
$IdentifyingNumber = $application.PSChildName
$InstallDate = $application.InstallDate
$RegOwner = $null
$vendor = $application.Publisher
if ($DisplayName -ne $null -or $DisplayVersion -ne $null -or $HelpLink -ne $null -or $IdentifyingNumber -ne $null -or $InstallDate -ne $null -or $vendor -ne $null ) {
Add-Content -Path 'c:\scripts\Inventories\SoftwareInventory.csv' "$hostname,$DisplayName,$DisplayVersion,$HelpLink,$IdentifyingNumber,$InstallDate,$RegOwner,$Vendor"
}
}