powershell-2.0

How to open image.png using ps1 script?

人走茶凉 提交于 2020-02-02 11:08:30
问题 Setting the below $usbDriveLetter variable to automatically find the USB drive letter, and using that variable to open an image on the USB doesn't work. It literally prints "G:\image.png" in the cmd. $usbDriveLetter = (gwmi win32_volume -f 'label=''USB_NAME_HERE''').Name; "$usbDriveLetter" + "image.png" But if I don't use a var and make "G:\" static in the PowerShell script, the image opens just fine. G:\image.png So what am I doing wrong here? How do we dynamically open images using ps1

What is an equivalent of *Nix 'cut' command in Powershell?

孤者浪人 提交于 2020-02-01 12:16:28
问题 I have following content in a configuration file (sample.cfg), Time_Zone_Variance(Mins):300 Alert_Interval(Mins):2 Server:10.0.0.9 Port:1840 I'm trying to store an each values after the : by using split in PowerShell. but i'm not able to produce require output. Can someone tell me how to use PowerShell split for the above problem ? 回答1: You can read the contents of the file using Get-Content , then pipe each line through ForEach-Object , then use the split command on each line, taking the

What is an equivalent of *Nix 'cut' command in Powershell?

混江龙づ霸主 提交于 2020-02-01 12:16:22
问题 I have following content in a configuration file (sample.cfg), Time_Zone_Variance(Mins):300 Alert_Interval(Mins):2 Server:10.0.0.9 Port:1840 I'm trying to store an each values after the : by using split in PowerShell. but i'm not able to produce require output. Can someone tell me how to use PowerShell split for the above problem ? 回答1: You can read the contents of the file using Get-Content , then pipe each line through ForEach-Object , then use the split command on each line, taking the

Can't use Get-Service –ComputerName on remote computer

我是研究僧i 提交于 2020-01-31 05:37:06
问题 I have a windows 2003 box setup with virtual box and I can't powershell to work with it. I try this on my windows 7 machine Get-Service –ComputerName myserver I get back Get-Service : Cannot open Service Control Manager on computer 'myserver'. This operation might require other privileges. At Script1.ps1:2 char:4 + gsv <<<< -cn myserver + CategoryInfo : NotSpecified: (:) [Get-Service], InvalidOperationException + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell

PowerShell unable to use enum MultipleInstances

心不动则不痛 提交于 2020-01-30 11:38:06
问题 I am looking to use Powershell to set "if the task is already running, then the following rules applies: to "Do not start a new instance" my powershell script looks like below: $Task = Get-ScheduledTask -TaskName "MyJob" $Task.Settings.MultipleInstances= "StopExisting" Set-ScheduledTask -User "USER" -Password "PASS" $Task I get error as : Exception setting "MultipleInstances": "Cannot convert value "StopExisting" to type "Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask

Running remote scripts in powershell

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-24 20:09:31
问题 I've successfully got winrm working and I'm able to run Enter-PSSession my-machine in the shell and subsequently enter commands. However, when I try to run a script that starts up a remote session, all subsequent calls are run on the local machine. For instance: PS> test.ps1 Contents of test.ps1 Enter-PSSession remote-pcname gc env:computername prints out local-pcname instead of remote-pcname any idea why the script file is not honoring the remote session? It is definitely successfully

Running remote scripts in powershell

自古美人都是妖i 提交于 2020-01-24 20:05:19
问题 I've successfully got winrm working and I'm able to run Enter-PSSession my-machine in the shell and subsequently enter commands. However, when I try to run a script that starts up a remote session, all subsequent calls are run on the local machine. For instance: PS> test.ps1 Contents of test.ps1 Enter-PSSession remote-pcname gc env:computername prints out local-pcname instead of remote-pcname any idea why the script file is not honoring the remote session? It is definitely successfully

Running remote scripts in powershell

社会主义新天地 提交于 2020-01-24 20:04:28
问题 I've successfully got winrm working and I'm able to run Enter-PSSession my-machine in the shell and subsequently enter commands. However, when I try to run a script that starts up a remote session, all subsequent calls are run on the local machine. For instance: PS> test.ps1 Contents of test.ps1 Enter-PSSession remote-pcname gc env:computername prints out local-pcname instead of remote-pcname any idea why the script file is not honoring the remote session? It is definitely successfully

LiteralPath option for cmdlet

安稳与你 提交于 2020-01-24 08:40:07
问题 In most example that I see in tutorials and books, the -LiteralPath option is almost never used by default (the -Path option seems to be preferred). Because the -LiteralPath option allows to use reserved characters (e.g. []), I don't understand why it is not used more often (if not, all the time). Is it because it is preferred to escape reserved characters manually, because it has a high performance cost, because not all cmdlet support this option or because something else? 回答1: One thing to

Measure-Object -sum all counterSamples from continuous get-counter

。_饼干妹妹 提交于 2020-01-23 18:54:20
问题 I am trying to write a PowerShell script that will continuously poll a performance counter every N seconds then sum the values returned by the counter. My end goal is to have results for a dozen or so counters get rolled up and shipped off to a Graphite server for monitoring and reporting. so far this is what I have cobbled together for a particular counter, i'm just not sure how to get a couple of things in the land of PowerShell magic voodoo. I can't figure out how to get the Job ID as an