powershell

Trying to combine replace and new-item in powershell

元气小坏坏 提交于 2020-12-27 05:39:11
问题 I have a task to make changes to some Config files in a Directory, and the files that need changing are 7, all starting with "Monitoring_Tran_xx". Within these files there are certain values (TransactionID="01" AgreedResponseTime="500" SearchProfileID="216") that need changing but not present across all 7, and will need to check if they are present before replace or creating them. Also I am trying to insert a new parameter(using new-item) if a certain parameter is equal to a certain value e.g

PowerShell function parameters syntax

荒凉一梦 提交于 2020-12-26 06:55:36
问题 Why do the Write-Host outside of the function work different than inside of the function? It seems like somehow the parameters variables are changing from what I declared it to be... function a([string]$svr, [string]$usr) { $x = "$svr\$usr" Write-Host $x } $svr = 'abc' $usr = 'def' $x = "$svr\$usr" Write-Host $x a($svr, $usr) Results… abc\def abc def\ 回答1: Don't call functions or cmdlets in PowerShell with parentheses and commas (only do this in method calls)! When you call a($svr, $usr) you

Output file doesn't match Write-Host

我们两清 提交于 2020-12-26 04:43:25
问题 When I Write-Host from my .ps1 file I see: Parentfolder >> ChildFolder When I output to a file, I see: ParentFolder >> ChildFolder I am using a simple write-host ($childgroup.name), ">>", ($object.samaccountname) When I try to output the same information using Return , Out-File , Export to CSV , etc... I get 3 lines for what Write-Host prints as a single line . I just want the output file to be in the same format as the Write-Host output. as requested: function getchildgroups($groupname) { #

German Umlauts in Powershell called by vbs

。_饼干妹妹 提交于 2020-12-26 04:01:21
问题 i do have a ps1 file, which create a Link create-link.ps1 $path = $env:HOMESHARE + "\My Projects\" If(!(test-path $path)) { New-Item -ItemType Directory -Force -Path $path } $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut($env:HOMESHARE + "\My Projects\" + "linkname.lnk") $Shortcut.TargetPath = "\\path\for\link" $Shortcut.Description = "äöüß" $Shortcut.IconLocation = $env:SYSTEMROOT + "\\system32\\shell32.dll,3" $Shortcut.Save() I also do have a vbs file

German Umlauts in Powershell called by vbs

為{幸葍}努か 提交于 2020-12-26 04:00:11
问题 i do have a ps1 file, which create a Link create-link.ps1 $path = $env:HOMESHARE + "\My Projects\" If(!(test-path $path)) { New-Item -ItemType Directory -Force -Path $path } $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut($env:HOMESHARE + "\My Projects\" + "linkname.lnk") $Shortcut.TargetPath = "\\path\for\link" $Shortcut.Description = "äöüß" $Shortcut.IconLocation = $env:SYSTEMROOT + "\\system32\\shell32.dll,3" $Shortcut.Save() I also do have a vbs file

How delete a line having a word quickly in multiple large files using powershell

回眸只為那壹抹淺笑 提交于 2020-12-26 03:45:14
问题 How delete a line having a word quickly in multiple large files using PowerShell i am using the below code but it take long time $files = Get-ChildItem "D:\mjautomation\v19.0\filesdd\" foreach ($file in $files) { $c = Get-Content $file.fullname | where { $_ -notmatch "deletethisline" } $c | Set-Content $file.fullname 回答1: The following should be reasonably fast due to use of switch -File, but note that it requires reading each file into memory as a whole (minus the excluded lines): foreach (

Keep $ for Powershell variable in VS code snippet

假装没事ソ 提交于 2020-12-25 18:53:52
问题 I’m able to save my code snippets with tabbed spacing in VS code for Powershell, but it keeps ignoring my variables by not displaying the $ for my variables when I call the snippet. It will just paste in the name and omit the $ . How do you get VS code to paste in the $ when you select your code snippet? Here is the VS Code JSON file I'm using for my "template" snippet { // Place your snippets for powershell here. Each snippet is defined under a snippet name and has a prefix, body and //

How to escape schtasks /tr arguments

最后都变了- 提交于 2020-12-25 13:43:25
问题 I need to schedule a PowerShell task like following: powershell.exe -file ..\Execute\execute.ps1 And I have tried assigning it to an argument $Argument then pass it to schtasks like following: $Argument = "powershell.exe -file '..\Execute\execute.ps1'" schtasks /create /tn "SOE_Checks" /tr $Argument /sc DAILY /st 05:00 /ru "System" /rl HIGHEST /f but after running above code, nothing happened - while the task is created successfully, it appears not to run. I have also tried assigning it to

How to escape schtasks /tr arguments

假如想象 提交于 2020-12-25 13:43:00
问题 I need to schedule a PowerShell task like following: powershell.exe -file ..\Execute\execute.ps1 And I have tried assigning it to an argument $Argument then pass it to schtasks like following: $Argument = "powershell.exe -file '..\Execute\execute.ps1'" schtasks /create /tn "SOE_Checks" /tr $Argument /sc DAILY /st 05:00 /ru "System" /rl HIGHEST /f but after running above code, nothing happened - while the task is created successfully, it appears not to run. I have also tried assigning it to

Why doesn't this msiexec.exe command work in powershell?

空扰寡人 提交于 2020-12-25 04:22:21
问题 I am trying to execute the following command through powershell, in a script invoked by an Advanced Installer generated installation program. The problem is that when the script executes, it chokes on a call to MSIEXEC.exe. More specifically, it puts up a windows dialog of the msiexec help screen. Ok so maybe it doesn't like the way advanced installer is executing it. So I take the actual line that is causing problems: msiexec.exe /q /i 'C:\Users\ADMINI~1\AppData\Local\Temp\mongo-server-3.4