I'm very new to Powershell. Im basically just using my C# logic and .net experience along with google to create this script. I dont understand why im getting the error:
Cannot process argument transformation on parameter 'machine'. Cannot convert value to type System.String
function IterateThroughMachineSubkeys{
(
[Parameter()]
[string]$machine,
[Microsoft.Win32.RegistryKey]$subKey
)
foreach($subKeyName in $subKey.GetSubKeyNames())
{
Write-Host -Object ([System.String]::Format("Machine: {0} Module: {1} Version: {2}",
$machine.ToString(), $subKeyName.ToString(),
$subKey.OpenSubKey([string]$subKeyName).GetValue("Version", "Not found", [Microsoft.Win32.RegistryValueOptions]::None)))
}
}
This is where im calling the function:
switch -CaseSensitive (ValidateConsoleInput((Read-Host).ToString()))
{
"E"
{
IterateThroughMachineSubkeys($machine.ToString(), $subKey)
}
"C"
{
Write-Host -Object "Enter the module name to be queried in the registry:"
GetSpecificSubkey($machine, $subkey, [string](Read-Host))
}
}