Hi,
I'm having a bit of trouble with a script i'm running.
The script successfully queries computers for a list of their installed software and displays the results in the powershell window.
I need to be able to write the results to a file instead and i'm a bit stuck on how to, is anybody able to help me and point me in the right direction please?
In a .vbs script i used to put something like this at the top of the code:
strOutFile = "C:\scripts\out.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFSO.CreateTextFile(strOutFile, True)
and make sure the required data line started objOutFile.Write "..."
but i'm not sure how to do it in powershell.
The code i'm using is this:
$COMPUTERS=IMPORT-CSV C:\scripts\serverlist.txt
FOREACH ($PC in $COMPUTERS) {
$computername=$PC.NameOfComputer
# Branch of the Registry
$Branch='LocalMachine'
# Main Sub Branch to open
$SubBranch="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
$registry=[microsoft.win32.registrykey]::OpenRemoteBaseKey('Localmachine',$computername)
$registrykey=$registry.OpenSubKey($Subbranch)
$SubKeys=$registrykey.GetSubKeyNames()
# Obtain software details
Foreach ($key in $subkeys)
{
$exactkey=$key
$NewSubKey=$SubBranch+"\\"+$exactkey
$ReadUninstall=$registry.OpenSubKey($NewSubKey)
$Value=$ReadUninstall.GetValue("DisplayName")
WRITE-HOST $computername, $Value
}
}
I know the write-host command is the i need to amend, but i'm not sure what to amend it to.
Any help would be greatly appreciated.
Thanks,
H
I'm having a bit of trouble with a script i'm running.
The script successfully queries computers for a list of their installed software and displays the results in the powershell window.
I need to be able to write the results to a file instead and i'm a bit stuck on how to, is anybody able to help me and point me in the right direction please?
In a .vbs script i used to put something like this at the top of the code:
strOutFile = "C:\scripts\out.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFSO.CreateTextFile(strOutFile, True)
and make sure the required data line started objOutFile.Write "..."
but i'm not sure how to do it in powershell.
The code i'm using is this:
$COMPUTERS=IMPORT-CSV C:\scripts\serverlist.txt
FOREACH ($PC in $COMPUTERS) {
$computername=$PC.NameOfComputer
# Branch of the Registry
$Branch='LocalMachine'
# Main Sub Branch to open
$SubBranch="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
$registry=[microsoft.win32.registrykey]::OpenRemoteBaseKey('Localmachine',$computername)
$registrykey=$registry.OpenSubKey($Subbranch)
$SubKeys=$registrykey.GetSubKeyNames()
# Obtain software details
Foreach ($key in $subkeys)
{
$exactkey=$key
$NewSubKey=$SubBranch+"\\"+$exactkey
$ReadUninstall=$registry.OpenSubKey($NewSubKey)
$Value=$ReadUninstall.GetValue("DisplayName")
WRITE-HOST $computername, $Value
}
}
I know the write-host command is the i need to amend, but i'm not sure what to amend it to.
Any help would be greatly appreciated.
Thanks,
H