I am trying to get the location of a usb named Foobar.
Running (Get-PsDrive -Name D).Description works in Powershell ISE but not in Powershell.
When running in Powershell ISE the result is Foobar
When running in Powershell I get nothing back (empty string)
What is the difference when running the same command in ISE and in the normal powershell?
Also is it possible to get a drive location reliably by the name/label of the device?
Thomas, I tested using this script:
clear-host
$x = Get-Psdrive | Where-object Name -like "?"
ForEach ($drv in $x) {
"$($drv.name) : $($drv.Description)"
}
I got the following result on 5.1 ISE 5.1.18362.1171 & CMD 5.1.18362.1171 and also on PS7 7.0.0 (all 64 Bit):
Since you're checking for D, I'm assuming it is a CD drive. Thus, it appears to be normal behavior? Not sure why you got different results.
Related
Is it possible, from a PowerShell script, to for example automate text box population, automate striking of the enter key inside of an installed program in Windows 10? Could anyone point me in the direction of relevant documentation?
Would a different alternative to PowerShell be more appropriate?
Thanks!
I know how to execute the program from PowerShell (PS C:> 'filepath\program.exe'). I also know how to kill the program from PowerShell (PS C:> stop-process -Name "program_name").
In trying to figure out how events are identified, I tried:
PS C:> $Events = Get-Event
PS C:> $Events[0] | Format-List -Property *
But it returns an error message: "Cannot index into a null array"
OBJECTIVES :-
I'm having trouble with something that should be relatively simple? Searched similar questions here but no cigar. I dont want to have to pass a command to the file as a Ps1 script (common suggestion). I'm hoping I can just right click, run with PowerShell and it works.
SITUATION :-
I have to automate uninstalling of software often. Rather than scour the registry for msiexec strings, I edited some PS code so I can search for what I want, then do whatever I need to do with the info I receive. The below runs fine in PowerShell ISE, but as a PS1 script (right click, run with PS) it outputs nothing on the screen.
CODE :-
$Prog = Read-Host -Prompt 'Input your Prog name'
Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match "$Prog"} | Select-Object -Property DisplayName, UninstallString
pause
Lets say at the prompt I search for 7-Zip in ISE I get this...
Input your Prog name: 7-zip
DisplayName UninstallString
----------- ---------------
7-Zip 19.00 (x64) C:\Program Files\7-Zip\Uninstall.exe
Running as a script, I get nothing output into the console?
Input your Prog name: 7-zip
Press Enter to continue...:
QUESTION :- What do I need to do to make the script behave like it does in the ISE console?
Many thanks for any assistance
P.S (<see what I did there, I'm new to the PowerShell game, thanks>)
It works in Powershell too, if you run it from Powershell Interactive Prompt or run using powershell -file "FILEPATH" in CMD/PowerShell, the output remains on the screen. But when you run directly with a double-click output doesn't stay persistent on the screen, instead when it reaches EOF then it quits. So, Add Read-Host or cmd /c pause at the end to stop the program at the end, to view output.
I have OpenSSH installed on Windows Server 2019 https://github.com/PowerShell/Win32-OpenSSH
SSH works great except for an issue with pipe ( | ) commands in Powershell SSH. I have successfully converted some of my | commands to ; example:
powershell Mount-VHD -Path D:/VMdir/tester.vhdx -PassThru | Get-Disk | Get-Partition | Get-Volume
becomes
powershell Mount-VHD -Path D:/VMdir/tester.vhdx -PassThru; Get-Disk; Get-Partition; Get-Volume
and it works fine, but I also have:
powershell (Get-VM tester | select-object MemoryMaximum).memorymaximum/1mb
and I can't get this one to work in SSH, works fine in windows though but not via SSH. I have tried a ; and & but it doesn't work. First why would the pipe commands work inside windows but not outside windows via ssh and any idea on how I can replace the pipe in the above command to get it work through ssh? The above command displays only a number (eg. 2048) it doesn't display any other info and that's what I need only a number.
Use "|" instead of | works perfectly.
I have seen many similar questions but none of them is related to the execution of a CMD command such as ipconfig from a PS script (.ps1).
If you type those commands on the PS console they work fine but once on a script they don't, below you can see an example:
PS C:\Users\TestQro> adb devices
List of devices attached
PS C:\Users\TestQro> adb devices | Select-String -Quiet List
True
returns True because the Select-String finds the word "List" in the response of the command "adb devices" which is the expected behavior. But if I go and put the same command into a .ps1 script file PS answers when running:
PS C:\TesterInfo> ./TunnerApp.ps1
cmdlet Write-Output at command pipeline position 1
Supply values for the following parameters: InputObject[0]:
How should I type the normal CMD commands inside of a script?
Why is it waiting for parameters on script but right in the console it works fine?
Based on your output there
PS C:\TesterInfo> ./TunnerApp.ps1
cmdlet Write-Output at command pipeline position 1
Supply values for the following parameters: InputObject[0]:
It looks like you have a Write-Output statement somewhere in your PowerShell script that does not have any input. Look for an empty Write-Output statement somewhere
What you're referring to as CMD commands are actually executables in the Windows or System32 folders (or some other PATH environment variable path). As such, you can call them like you would any executable using the call operator:
& "$Env:SystemRoot\System32\IPCONFIG.exe"
about_Operators
I am trying to get NAS drive parameters using PS commands. The below command, however, is not getting any value when called via Python code by connecting to remote server. However, if I run it by copy-pasting into that remote server it gives output.
$nas = Get-PSDrive | Where-Object {$_.DisplayRoot -like '*jkl.com*'}
write-host $nas
No error and no output when run through Python code.