powershell

Passing arguments as array to PowerShell function

我的梦境 提交于 2021-02-08 03:08:52
问题 I'm trying to figure out how I can pass multiple strings as an array to a powershell function. function ArrayCount([string[]] $args) { Write-Host $args.Count } ArrayCount "1" "2" "3" ArrayCount "1","2","3" ArrayCount @("1","2","3") Prints 2 0 0 How can I pass an array with 3 values to the ArrayCount function? Why is the Count zero for some of the invocations? 回答1: In PowerShell, $args is a automatic variable that refers to unnamed arguments. Just change your parameter name: function

Passing arguments as array to PowerShell function

﹥>﹥吖頭↗ 提交于 2021-02-08 03:07:26
问题 I'm trying to figure out how I can pass multiple strings as an array to a powershell function. function ArrayCount([string[]] $args) { Write-Host $args.Count } ArrayCount "1" "2" "3" ArrayCount "1","2","3" ArrayCount @("1","2","3") Prints 2 0 0 How can I pass an array with 3 values to the ArrayCount function? Why is the Count zero for some of the invocations? 回答1: In PowerShell, $args is a automatic variable that refers to unnamed arguments. Just change your parameter name: function

PowerShell script to copy files but not subfolders to SFTP and move to subfolder once done

筅森魡賤 提交于 2021-02-08 02:12:25
问题 I am using the following script to copy files from my local folder to SFTP. Once I upload the file I then want to move the file to a subfolder. I want to upload only files in the C:\Users\Administrator\Desktop\ftp folder, and not files in the other subfolders. param ( $backupPath = "C:\Users\Administrator\Desktop\ftp\moved" ) # Load the Assembly and setup the session properties try { # Load WinSCP .NET assembly Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll" $session = New-Object

PowerShell script to copy files but not subfolders to SFTP and move to subfolder once done

穿精又带淫゛_ 提交于 2021-02-08 02:11:23
问题 I am using the following script to copy files from my local folder to SFTP. Once I upload the file I then want to move the file to a subfolder. I want to upload only files in the C:\Users\Administrator\Desktop\ftp folder, and not files in the other subfolders. param ( $backupPath = "C:\Users\Administrator\Desktop\ftp\moved" ) # Load the Assembly and setup the session properties try { # Load WinSCP .NET assembly Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll" $session = New-Object

Executing command using Plink does not work, but does in PuTTY

对着背影说爱祢 提交于 2021-02-08 02:07:35
问题 I am trying to create a PowerShell script to SSH into a Raspberry Pi and perform some commands. I am using Plink to SSH into the Pi over command line. However I have to SSH into the Pi user which runs in lshell. I can PuTTY into the Pi with zero issues, but when using Plink I get an error saying the command I am using is forbidden. I am trying to use su which works when using PuTTY by not Plink. The error I get is below: plink : *** forbidden char/command over SSH: "su" At line:1 char:1 +

vagrant error the version of powershell on this host is less than required

萝らか妹 提交于 2021-02-08 01:28:43
问题 I have a problem with vagrant. 1) I have Windows 7. 2) Run script in Windows PowerShell 3) Code that i execute: PS D:\vagrants> vagrant --debug 4) my windows Path entry: C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\UCRT\;C:\Program Files\Intel\UCRT\;C:\Program Files (x86)\Intel

vagrant error the version of powershell on this host is less than required

断了今生、忘了曾经 提交于 2021-02-08 01:21:53
问题 I have a problem with vagrant. 1) I have Windows 7. 2) Run script in Windows PowerShell 3) Code that i execute: PS D:\vagrants> vagrant --debug 4) my windows Path entry: C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\UCRT\;C:\Program Files\Intel\UCRT\;C:\Program Files (x86)\Intel

Why is this regular expression failing to match the second 6 digit number?

喜欢而已 提交于 2021-02-07 23:46:41
问题 I can't understand why the following PowerShell is not working: ([regex]"(^|\D)(\d{6})(\D|$)").Matches( "123456 123457" ).Value The code above code produces: 123456 Why is it not matching both numbers? 回答1: The "(^|\D)(\d{6})(\D|$)" regex matches and consumes a non-digit char before and after 6 digits (that is, the space after 123456 is consumed during the first iteration). Use a non-consuming construct, lookbehind and lookahead: "(?<!\d)\d{6}(?!\d)" See a .NET regex demo. The (?<!\d)

Why is this regular expression failing to match the second 6 digit number?

走远了吗. 提交于 2021-02-07 23:44:15
问题 I can't understand why the following PowerShell is not working: ([regex]"(^|\D)(\d{6})(\D|$)").Matches( "123456 123457" ).Value The code above code produces: 123456 Why is it not matching both numbers? 回答1: The "(^|\D)(\d{6})(\D|$)" regex matches and consumes a non-digit char before and after 6 digits (that is, the space after 123456 is consumed during the first iteration). Use a non-consuming construct, lookbehind and lookahead: "(?<!\d)\d{6}(?!\d)" See a .NET regex demo. The (?<!\d)

Where solution build order is saved

拥有回忆 提交于 2021-02-07 21:01:50
问题 I have a solution which contains multiple projects (csproj & btproj). I'm actually running BizTalk 2013 R2, so I'm developing under Visual Studio 2013. I have many powershell scripts to deploy my applications and I have to enhance them. I need to read or determine the projects build order of a solution to deploy my assemblies in this order. Ok I can get it under "Project->Project Dependencies", but where are these informations stored ? Or how can I determine them programatically with