powershell-2.0

How to use the “-Property” parameter for PowerShell's “Measure-Object” cmdlet?

只谈情不闲聊 提交于 2020-07-08 06:21:52
问题 Why does $a = GPS AcroRd32 | Measure $a.Count work, when GPS AcroRd32 | Measure -Property Count doesn't? The first example returns a value of 2 , which is what I want, an integer. The second example returns this: Measure-Object : Property "Count" cannot be found in any object(s) input. At line:1 char:23 + GPS AcroRd32 | Measure <<<< -Property Count + CategoryInfo : InvalidArgument: (:) [Measure-Object], PSArgumentException + FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft

Chain commands on the PowerShell command line (like POSIX sh &&) [duplicate]

烈酒焚心 提交于 2020-07-06 07:10:38
问题 This question already has answers here : conditional execution (&& and ||) in powershell (7 answers) Closed 25 days ago . Does PowerShell have an equivalent to this command construct from sh (and derivatives): $ cmd1 && cmd2 where cmd2 is only run when cmd1 exits sucessfully? I know you can combine commands with a semicolon. However, this disregards the exit status of commands. 回答1: There is no direct analog to && or ||. There are several discussions on alternatives though. Here is one

Chain commands on the PowerShell command line (like POSIX sh &&) [duplicate]

落爺英雄遲暮 提交于 2020-07-06 07:09:53
问题 This question already has answers here : conditional execution (&& and ||) in powershell (7 answers) Closed 25 days ago . Does PowerShell have an equivalent to this command construct from sh (and derivatives): $ cmd1 && cmd2 where cmd2 is only run when cmd1 exits sucessfully? I know you can combine commands with a semicolon. However, this disregards the exit status of commands. 回答1: There is no direct analog to && or ||. There are several discussions on alternatives though. Here is one

Download files from SFTP server using PowerShell [closed]

家住魔仙堡 提交于 2020-07-05 11:42:45
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Improve this question I need to download files from SFTP server to a local machine using a PowerShell script. The API/library that will be used for the download needs to be able to monitor results of the transfer, log the transfer, and also to archive/move the downloaded files.

CPU and memory usage in percentage for all processes in Powershell

天大地大妈咪最大 提交于 2020-06-10 05:18:50
问题 Is there a way for viewing CPU and memory utilization in percentage for all running processes in PowerShell ? I have tried the following: Get-Process | %{"Process={0} CPU_Usage={1} Memory_Usage={2}" -f $_.ProcessName,[math]::Round($_.CPU),[math]::Round($_.PM/1MB)} Along with it I have parsed this information and calculated memory usage percentage from total memory, but couldn't get the same for CPU since by this command it show CPU time division in processes not utilization per se. Used the

Power Shell CSV to AD

帅比萌擦擦* 提交于 2020-05-17 08:54:05
问题 Maybe someone can to help? I have a script it take parameters from scv and put them to AD, script work without mistakes but I`m does not have results from some reasone. Please help! Import-CSV -Path "$home\desktop\Scripts\test4.scv" | ForEach-Object -process {Write-Host $_ } {Set-ADuser|]= -Identity $_.DisplayName -extensionattribute5 $_.extensionattribute5} example scv 回答1: According to the docs, the -Identity parameter on Set-ADUser must be one of A distinguished name A GUID (objectGUID) A

How can I change the version of powershell I'm running in from within the script?

♀尐吖头ヾ 提交于 2020-05-15 07:45:39
问题 I would like to run my powershell script in v2 mode. Is it possible to do this without having a wrapper script? So for example, I can do this now if I can two files. MainContent.ps1 write-output 'run some code' Read-Host -Prompt "Scripts Completed : Press any key to exit" Wrapper.ps1 powershell -version 2 -file 'MainContent.ps1' This will work but I'm hoping I don't need to have this second wrapper file because I'm creating a whole bunch of these ps1 scripts, and having wrapper files will

Convert multiple PowerShell scripts into an Exe file

笑着哭i 提交于 2020-05-13 14:37:29
问题 I have few powershell script in orders. Can I convert the powershell scripts into one exe file ? I need set up it to run in order. Example, once installing with first script, second script need be installed and followed by 3,4,5 scripts. 回答1: In the simplest case, you can use the following approach to merge your scripts into a single script that you can then package as an executable: $scripts = 'script1.ps1', 'script2.ps1', 'script3.ps1' (Get-Item $scripts | ForEach-Object { "& {{`n{0}`n}}"

Convert multiple PowerShell scripts into an Exe file

萝らか妹 提交于 2020-05-13 14:36:08
问题 I have few powershell script in orders. Can I convert the powershell scripts into one exe file ? I need set up it to run in order. Example, once installing with first script, second script need be installed and followed by 3,4,5 scripts. 回答1: In the simplest case, you can use the following approach to merge your scripts into a single script that you can then package as an executable: $scripts = 'script1.ps1', 'script2.ps1', 'script3.ps1' (Get-Item $scripts | ForEach-Object { "& {{`n{0}`n}}"

What is the syntax to subscribe to an object's static event in PowerShell?

橙三吉。 提交于 2020-05-10 14:26:52
问题 Register-ObjectEvent looks for a object instance in the required parameter InputObject . What is the syntax for an object's static ( Shared ) event? UPDATE : Correct syntax for TimeChanged: $systemEvents = [Microsoft.Win32.SystemEvents] $timeChanged = Register-ObjectEvent -InputObject $systemEvents -EventName 'TimeChanged' -Action { Write-Host "Time changed" } Unfortunately, the SystemEvents will not be signaled in PowerShell ISE . Here's a sample using an object's staic event that works