I have three main questions.
-
System.Secuirty.SecureString I’m using "$pass = Read-Host "Prompt: " -AsSecureString
The goal is to be able to use $pass for the winrm switch -p:$pass It doesn’t like this why? -
I have a Command handler function Run-Command() which takes $command as an arg. $command is a hash table that relates to the selected method a user wants to run based on the menu’s. When function is called within the script the value of $command wrote out before and its listed as System.Collections.Hashtable after the script is run you can check that variable and run the command manually using the var and it works. What am I missing?
##############################
[*] 1:GetPowerManagementCapabilities --> Press 1 for this Option
[*] Q: QUIT --> Press Q to Quite
Please make a selection: 1
This value of command System.Collections.Hashtable
winrm : Error: Unknown operation name: ''
At line:1 char:1
+ winrm -u:root -p:password -r:https://10.0.147.2/wsman -auth:basic -en ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Error: Unknown operation name: '':String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
PS C:\WINDOWS\system32> $command
Name Value
---- -----
Command enumerate
URI cimv2/CIM_PowerManagementCapabilities
PS C:\WINDOWS\system32> winrm $command.Command $command.URI -u:$rac_un -p: -r:https://$rac_ip/wsman -auth:basic -encoding:utf-8 -SkipCNCheck -SkipCACheck
DCIM_CSPowerManagementCapabilities
ElementName = Power Management Capabilities
InstanceID = DCIM:pwrmgtcap1
PowerChangeCapabilities = 3, 4, 7, 8
PowerStatesSupported = 2, 5, 8, 10, 11, 12
RequestedPowerStatesSupported = 2, 5, 8, 10, 11, 12
- I putthis together yesterday just playing to see if I could get something that would work. Which led to the menu interfaces and switch statements. Is there a better design flow that I could use for a simple project like this one please let me know.
Eventually once all of the querying is done I will look to add methods that make config changes or schedule jobs.
$PS_METHODS = @{
SYSTEM_METHODS = @{
GetSystemView = @{
Command = 'enumerate';
URI = "cimv2/root/dcim/DCIM_SystemView"
}
GetVideoView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_VideoView'
}
GetSystemString = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_SystemString'
}
GetComputerSystem = @{
Command = 'enumerate';
URI = 'cimv2/CIM_ComputerSystem'
}
GetCPUView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_CPUView'
}
GetFanViews = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_FanView'
}
GetMemoryView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_MemoryView'
}
GetPCIDeviceView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_PCIDeviceView'
}
GetPowerSupplyView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_PowerSupplyView'
}
GetSystemAttribute = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_SystemAttribute'
}
GetSystemEnumeration = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_SystemEnumeration'
}
GetSystemInteger = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_SystemInteger'
}
}
BIOS_METHODS = @{
GetBIOSEnumeration = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_BIOSEnumeration'
}
GetBIOSInteger = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_BIOSInteger'
}
GetBIOSString = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_BIOSString'
}
}
FC_METHODS = @{
GetFCAttribute = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_FCAttribute'
}
GetFCEnumeration = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_FCEnumeration'
}
GetFCCapabilities = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_FCCapabilities'
}
GetFCInteger = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_FCInteger'
}
GetFCstatistics = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_FCStatistics'
}
GetFCString = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_FCString'
}
GetFCView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_FCView'
}
}
NIC_METHODS = @{
GetNICAttributes = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_NICAttribute'
}
GetNICEnumeration = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_NICEnumeration'
}
GetNICCapabilities = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_NICCapabilities'
}
GetNICInteger = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_NICInteger'
}
GetNICStatistics = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_NICStatistics'
}
GetNICString = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_NICString'
}
GETNICView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_NICView'
}
}
RAID_METHODS = @{
GetControllerView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_ControllerView'
}
GetEnclosureView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_EnclosureView'
}
GetPhysicalDiskView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_PhysicalDiskView'
}
GetRAIDEnumeration = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_RAIDEnumeration'
}
GetRAIDInteger = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_RAIDInteger'
}
GetRAIDString = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_RAIDString'
}
GetVirtualDiskView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_VirtualDiskView'
}
}
iDRAC_METHODS = @{
GetiDRACCardAttributes = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_iDRACCardAttribute'
}
GetiDRACCardEnumeration = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_iDRACCardEnumeration'
}
GetiDRACCardInteger = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_iDRACCardInteger'
}
GetiDRACCardString = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_iDRACCardString'
}
GetiDRACCardView = @{
Command = 'enumerate';
URI = 'cimv2/root/dcim/DCIM_iDRACCardView'
}
}
POWER_METHODS = @{
GetPowerManagementCapabilities = @{
Command = 'enumerate';
URI = 'cimv2/CIM_PowerManagementCapabilities'
}
}
}
Function globals {
# Init Vars
$global:rac_un = Read-Host "[*] Enter iDRAC username: "
$global:rac_pwd = Read-Host "Enter iDRAC Password: " -AsSecureString
$global:rac_ip = Read-Host "[*] Enter iDRAC IP Address: "
$global:method = $PS_METHODS
}
Function Top-Menu {
Param(
[string]$Title = ''
)
cls
Write-Host "###############$Title###############`n" -ForegroundColor Cyan
Write-Host "[*] 1:SYSTEM METHODS --> Press 1 for this Option" -ForegroundColor Cyan
Write-Host "[*] 2:BIOS METHODS --> Press 2 for this Option" -ForegroundColor Cyan
Write-Host "[*] 3:FC METHODS --> Press 3 for this Option" -ForegroundColor Cyan
Write-Host "[*] 4:NIC METHODS --> Press 4 for this Option" -ForegroundColor Cyan
Write-Host "[*] 5:RAID METHODS --> Press 5 for this Option" -ForegroundColor Cyan
Write-Host "[*] 6:iDRAC METHODS --> Press 6 for this Option" -ForegroundColor Cyan
Write-Host "[*] 7:POWER METHODS --> Press 7 for this Option" -ForegroundColor Cyan
Write-Host "[*] Q: QUIT --> Press Q to Quite" -ForegroundColor Cyan
}
Function Power-Menu {
Param (
[string]$power_title = ''
)
cls
Write-Host "###############$drac_title###############`n" -ForegroundColor Cyan
Write-Host "[*] 1:GetPowerManagementCapabilities --> Press 1 for this Option" -ForegroundColor Cyan
Write-Host "[*] Q: QUIT --> Press Q to Quite" -ForegroundColor Cyan
}
Function Run-Command(){
Param (
[parameter(Mandatory=$true, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[String[]]
$command
)
Write-Host "This value of command $command"
Invoke-Expression "winrm $($command.command) $($command.URI) -u:$rac_un -p:calvin -r:https://$rac_ip/wsman -auth:basic -encoding:utf-8 -SkipCNCheck -SkipCACheck"
}
Function Main {
Intro
globals
do {
Top-Menu
$input = Read-Host "Please make a selection"
switch ($input) {
1 {System-Menu}
2 {Bios-Menu}
3 {FC-Menu}
4 {NIC-Menu}
5 {RAID-Menu}
6 {iDRAC-Menu}
7 {
do {
Power-Menu
$selection = Read-Host "Please make a selection"
switch ($selection) {
1 {$global:command = $($method.POWER_METHODS.GetPowerManagementCapabilities); Run-Command($command)}
}
}
until($selection -eq 'q' -or $selection -ne $null)
}
}
}
until ($input -eq 'q' -or $input -ne $null)
}
Main