- I am trying to export the output of the script below to csv. 2) I want to bypass the execution policy.
My goal is have the person run the script or executable (.ps1 converted to .exe) and have it grab the information and export the data to their root (c:) drive.
I’ve tried looking at other scripts where the export-csv works, but can’t seem to nail down the positioning.
Many thanks in advance
======================================================
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[Parameter(ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string[]]
$ComputerName = $env:COMPUTERNAME,
[Parameter(Position=0)]
[string[]]$Property
)
begin {
$RegistryLocation = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\',
'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\'
$HashProperty = @{}
$SelectProperty = @('ProgramName','ProgramVersion','ComputerName')
if ($Property) {
$SelectProperty += $Property | export c:\test.csv
}
}
process {
foreach ($Computer in $ComputerName) {
$RegBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
foreach ($CurrentReg in $RegistryLocation) {
if ($RegBase) {
$CurrentRegKey = $RegBase.OpenSubKey($CurrentReg)
if ($CurrentRegKey) {
$CurrentRegKey.GetSubKeyNames() | ForEach-Object {
if ($Property) {
foreach ($CurrentProperty in $Property) {
$HashProperty.$CurrentProperty = ($RegBase.OpenSubKey("$CurrentReg$_")).GetValue($CurrentProperty)
}
}
$HashProperty.ComputerName = $Computer
$HashProperty.ProgramName = ($DisplayName = ($RegBase.OpenSubKey("$CurrentReg$_")).GetValue('DisplayName'))
$HashProperty.ProgramVersion = ($DisplayName = ($RegBase.OpenSubKey("$CurrentReg$_")).GetValue('DisplayVersion'))
if ($DisplayName) {
New-Object -TypeName PSCustomObject -Property $HashProperty |
Select-Object -Property
}
}
}
}
}
}
}
}