powershell-core

PowerShell Core Script deployed as AWS Lambda function fails to remote connect into Windows EC2 Instance using the Commandlet new-pssession

爱⌒轻易说出口 提交于 2021-02-19 07:34:07
问题 AWS Recently announced Lambda Support for PowerShell Core. Reference URL https://aws.amazon.com/blogs/developer/announcing-lambda-support-for-powershell-core/ Followed the steps given in the URL and deployed below Powershell Core script as a Lambda Function. Script: #Requires -Modules @{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.335.0'} $pw = convertto-securestring -AsPlainText -Force -String "Password" $cred = new-object -typename System.Management.Automation.PSCredential

How to pass a custom function inside a ForEach-Object -Parallel

安稳与你 提交于 2021-02-18 06:27:29
问题 I can't find a way to pass the function. Just variables. Any ideas without putting the function inside the ForEach loop? function CustomFunction { Param ( $A ) Write-Host $A } $List = "Apple", "Banana", "Grape" $List | ForEach-Object -Parallel { Write-Host $using:CustomFunction $_ } 回答1: The solution isn't quite as straightforward as one would hope: function CustomFunction { Param ($A) "[$A]" } # Get the function's definition *as a string* $funcDef = $function:CustomFunction.ToString() "Apple

How to pass a custom function inside a ForEach-Object -Parallel

点点圈 提交于 2021-02-18 06:26:49
问题 I can't find a way to pass the function. Just variables. Any ideas without putting the function inside the ForEach loop? function CustomFunction { Param ( $A ) Write-Host $A } $List = "Apple", "Banana", "Grape" $List | ForEach-Object -Parallel { Write-Host $using:CustomFunction $_ } 回答1: The solution isn't quite as straightforward as one would hope: function CustomFunction { Param ($A) "[$A]" } # Get the function's definition *as a string* $funcDef = $function:CustomFunction.ToString() "Apple

Exclude the JSON property only if it exists - Powershell

烈酒焚心 提交于 2021-02-08 11:41:24
问题 I have two different JSONs and I would like to remove streets from the JSON object if only it exists under Address which is an array. I am trying to do this in powershell. I can get my script working and remove the streets but I only want to run the exclude line of command if the address has the streets property. { "Customer": [{ "id": "123" }], "address": [{ "$type": "Home", "name": "Houston", "streets": [{ "name": "Union", "postalCode": "10" }] }, { "$type": "Office", "name": "Hawai",

Getting home directory?

依然范特西╮ 提交于 2021-02-04 16:59:06
问题 I'm trying to get a directory off of the user's home directory in a script. This is what I'm trying, but the ~ is interperated as a literal instead of expanding to the home directory. Is there anyway to get it to expand? If not, can I get the home directory another way? $mySourceDir = "~/Projects/svn/myProject/trunk" # Single quote also does not expand cd $mySourceDir This is using the PS 6 beta on OSX. 回答1: In PowerShell, the most robust way to refer to the current user's home directory is

What is the equivalent of 'nohup' in linux PowerShell?

*爱你&永不变心* 提交于 2021-01-01 06:40:42
问题 I very well know existence of duplicate question. But that question is marked answered and I don't think it at all answers the original question. The $ nohup command keeps executing command even if the parent process (shell) of nohup dies. More info here: What's the difference between nohup and ampersand. In case of Win32 api, I see line When the system is terminating a process, it does not terminate any child processes that the process has created. Terminating a process does not generate

Can I debug a dependent assembly from a powershell module

こ雲淡風輕ζ 提交于 2020-12-13 07:19:57
问题 I have a project it has two (or more) projects. For example: Shared.Standard Utility.PoSH The second is a PowerShell binary module that depends on the Shared.Standard class library/project/assembly. Can I debug the Shared.Standard library while I execute commands from the compiled module in a PowerShell session? I'm particularly curious about required config in vscode. 来源: https://stackoverflow.com/questions/59445038/can-i-debug-a-dependent-assembly-from-a-powershell-module

Can I debug a dependent assembly from a powershell module

倖福魔咒の 提交于 2020-12-13 07:19:47
问题 I have a project it has two (or more) projects. For example: Shared.Standard Utility.PoSH The second is a PowerShell binary module that depends on the Shared.Standard class library/project/assembly. Can I debug the Shared.Standard library while I execute commands from the compiled module in a PowerShell session? I'm particularly curious about required config in vscode. 来源: https://stackoverflow.com/questions/59445038/can-i-debug-a-dependent-assembly-from-a-powershell-module

Determine the OS version, Linux and Windows from Powershell

半世苍凉 提交于 2020-12-01 01:31:29
问题 How can I determine the OS type, (Linux, Windows) using Powershell from within a script? The ResponseUri isn't recognised when this part of my script is ran on a Linux host. $UrlAuthority = $Request.BaseResponse | Select-Object -ExpandProperty ResponseUri | Select-Object -ExpandProperty Authority So I want an If statement to determine the OS type that would look similar to this: If ($OsType -eq "Linux") { $UrlAuthority = ($Request.BaseResponse).RequestMessage | Select-Object -ExpandProperty