powershell

What is the difference between dot (.) and ampersand (&) in PowerShell?

六月ゝ 毕业季﹏ 提交于 2021-02-18 04:48:22
问题 In PowerShell, what is the difference between using dot ( . ) and ampersand ( & ) when invoking a cmdlet, function, script file, or operable program? For example: . foo.sh1 & foo.sh1 There is a very similar question which has been incorrectly closed as a duplicate: Differences between ampersand (&) and dot (.) while invoking a PowerShell scriptblock. The questions are different and have completely different keywords and search rankings. The answer on What is the `.` shorthand for in a

How can I compare against FileSystemRights using Powershell?

♀尐吖头ヾ 提交于 2021-02-18 03:22:30
问题 I want to check whether a given user has access to a given folder - by checking if they have "Modify" access assigned to them. I thought that the PS for that would be: (Get-Acl .\myfolder).Access | ?{$_.IdentityReference -eq "BUILTIN\Users"} |?{$_.filesystemrights.value -contains "Modify"} But the final part of that isn't working - I get back no result. But I know that they have Modify access - if I put in: (Get-Acl .\myfolder).Access | ?{$_.IdentityReference -eq "BUILTIN\Users"} | select

How can I compare against FileSystemRights using Powershell?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-18 03:20:54
问题 I want to check whether a given user has access to a given folder - by checking if they have "Modify" access assigned to them. I thought that the PS for that would be: (Get-Acl .\myfolder).Access | ?{$_.IdentityReference -eq "BUILTIN\Users"} |?{$_.filesystemrights.value -contains "Modify"} But the final part of that isn't working - I get back no result. But I know that they have Modify access - if I put in: (Get-Acl .\myfolder).Access | ?{$_.IdentityReference -eq "BUILTIN\Users"} | select

How can I compare against FileSystemRights using Powershell?

别来无恙 提交于 2021-02-18 03:17:24
问题 I want to check whether a given user has access to a given folder - by checking if they have "Modify" access assigned to them. I thought that the PS for that would be: (Get-Acl .\myfolder).Access | ?{$_.IdentityReference -eq "BUILTIN\Users"} |?{$_.filesystemrights.value -contains "Modify"} But the final part of that isn't working - I get back no result. But I know that they have Modify access - if I put in: (Get-Acl .\myfolder).Access | ?{$_.IdentityReference -eq "BUILTIN\Users"} | select

Hide powershell output

こ雲淡風輕ζ 提交于 2021-02-17 15:14:35
问题 I have the following script: param([Parameter(Mandatory=$true)][string]$dest) New-Item -force -path "$dest\1\" -itemtype directory New-Item -force -path "$dest\2\" -itemtype directory New-Item -force -path "$dest\3\" -itemtype directory Copy-Item -path "C:\Development\1\bin\Debug\*" -destination "$dest\1\" -container -recurse -force Copy-Item -path "C:\Development\2\bin\Debug\*" -destination "$dest\2\" -container -recurse -force Copy-Item -path "C:\Development\3\bin\Debug\*" -destination "

batch renaming files using powershell

房东的猫 提交于 2021-02-17 06:47:08
问题 I am able to batch rename files in a working directory by using: Dir | %{Rename-Item $_ -NewName ("0{0}.wav" -f $nr++)} However I want the file rename to start at something other than zero. Say 0500, and rename sequentially in order. Dir | %{Rename-Item $_ -NewName ("0{500}.wav" -f $nr++)} returns error. How can I tell rename to start at a number other than 0? 回答1: You can initialize the counter beforehand to 500. Also, you don't need to use a ForEach-Object loop ( % ) for this, because the

Read text file and check for value in a specific position and change when true

五迷三道 提交于 2021-02-17 06:16:05
问题 I need to loop through multiple text files and check for a $ value in position 7 on each line of text and replace it with an * when found. But ONLY when it is in position 7. I do not want to change it if it is found in other positions. This is as far as I have gotten. Any help would be greatly appreciated. Get-ChildItem 'C:\*.txt' -Recurse | foreach $line in Get-Content $_ { $linePosition1to5 = $line.Substring(0,6) $linePosition7 = $line.Substring(6,1) $linePositionRest = $line.Substring(8)

Powershell gui textbox with multiple color lines

邮差的信 提交于 2021-02-17 05:50:28
问题 Im having trouble with powershell textbox here is the definition of it: $ResultsTextBox = New-Object System.Windows.Forms.TextBox $ResultsTextBox.Location = New-Object System.Drawing.Size(780,40) $ResultsTextBox.Size = New-Object System.Drawing.Size(450,340) i would like to create a function which output text to this text box but i would like to generate the text either red or green depending of my choice.. but when i do this: function LinkFn { $ResultsTextBox.clear() $SWITCH = Get

Function ported from Powershell 5 to Powershell 7 fails with “object reference not set to an instance of an object”

不想你离开。 提交于 2021-02-17 05:39:38
问题 Following code works as expected in powershell 5.1: function Get-Say([String] $Message, [String] $Voice = "Microsoft Irina Desktop") { Add-Type -AssemblyName System.speech $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer $speak.SelectVoice($Voice) $speak.Speak($Message) } However in powershell 7.1.0 (preview 5) execution is failing with "object reference not set to an instance of an object" and I'm actually lost. Googling does not help much since it looks like this error can be

Function ported from Powershell 5 to Powershell 7 fails with “object reference not set to an instance of an object”

萝らか妹 提交于 2021-02-17 05:39:12
问题 Following code works as expected in powershell 5.1: function Get-Say([String] $Message, [String] $Voice = "Microsoft Irina Desktop") { Add-Type -AssemblyName System.speech $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer $speak.SelectVoice($Voice) $speak.Speak($Message) } However in powershell 7.1.0 (preview 5) execution is failing with "object reference not set to an instance of an object" and I'm actually lost. Googling does not help much since it looks like this error can be