powershell

Adding PSCustomObject to Array gives Error, but works fine when debugging the code in Visual Studio Code

自作多情 提交于 2021-01-29 12:06:57
问题 When reading data from a CSV file and then trying to add a new custom object to the list I get an error when running the script, but when I try to debug the code I works as intended, and I can't figure out why it does work in debug mode, but not when run normally. $global:scanTime = Get-date $script:logfile_Database = Import-Csv -Path "${logSpace}\${CSV_logfileData}" -Delimiter ";" $currentLogfile = Get-ChildItem -Path "$($logfile.Path)\$($logfile.FileName)" -ErrorAction Stop $logfile_Data =

Powershell script help needed - Find word beginning with something and replace it

痞子三分冷 提交于 2021-01-29 11:43:11
问题 I'm trying to change a string within a file to a string with timestamp on the end but cant work out how to find the initial string using a regex in Powershell (Get-Content sw.js).replace('SW-cache-v.*', 'SW-cache-v'+$(Get-Date -format "s")) | Set-Content sw.js the SW-cache-v.* isn't working for me, I'm just not picking up the string in order to replace it. Any thoughts on how to do it? 回答1: In PowerShell, the -replace comparison operator uses regex matching with string replacement. $Replace =

Convert text file to PDF file using Powershell

时光毁灭记忆、已成空白 提交于 2021-01-29 11:28:04
问题 I have a text file that has simple firmware versions on it. I need to convert the text file to a secure pdf file using powershell scripts. Also, Is there a way to put a date and timestamp on the file when its converted? I don't quite know how to do it I'm fairly new using powershell, thanks! 回答1: I got this to work with Word 2010, but it should work with 2007 as well: # File paths $txtPath = "C:\Users\Public\test.txt" $pdfPath = "C:\Users\Public\test.pdf" # Required Word Variables

Downloaded ChromeStandaloneSetup.exe with PowerShell is corrupt

偶尔善良 提交于 2021-01-29 11:10:37
问题 This is based on my previous question where I use the script in the accepted answer: https://stackoverflow.com/a/51933920/3737177 I manage to download the exe via a ps1 script, but it seems it is corrupt. If I compare it to a file downloaded through the browser they look the same. Same file version, same SHA, but the one downloaded with a script gets an error: If I try to execute it from the script ".\ChromeStandaloneSetup.exe /install" there is some more information, but this doesn't help

Which operator provides quicker output -match -contains or Where-Object for large CSV files

旧时模样 提交于 2021-01-29 10:55:28
问题 I am trying to build a logic where I have to query 4 large CSV files against 1 CSV file. Particularly finding an AD object against 4 domains and store them in variable for attribute comparison. I have tried importing all files in different variables and used below 3 different codes to get the desired output. But it takes longer time for completion than expected. CSV import: $AllMainFile = Import-csv c:\AllData.csv #Input file contains below EmployeeNumber,Name,Domain Z001,ABC,Test.com Z002

How to create multiple button with PowerShell?

我们两清 提交于 2021-01-29 10:38:18
问题 I would like to create multiple buttons. The button more than 50 buttons. But I do not want to create it one by one like what I did below. All the button function, size, are the same. Only the name is different. Anyone can help me please, and give an idea. Thank you very much. Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.Application]::EnableVisualStyles() $Form = New-Object system.Windows.Forms.Form $Form.ClientSize = New-Object System.Drawing.Point(973,1177) $Form.text =

Powershell command to retrieve Failover Cluster Disk Size/Free Space?

荒凉一梦 提交于 2021-01-29 10:37:22
问题 I'm using Powershell and attempting to retrieve the size, and available space, of a Physical Disk Resource. I want this code to run on one Windows Server 2008 R2 box (a monitoring server), and poll resources on three remote clusters on the same domain. 2 of the clusters are also running Windows Server 2008 R2, but one is running Windows Server 2012 (x64). The returned data will be inserted into a database as part of a monitoring app. Currently the code I'm using is: $clusters = "cluster1

Powershell can't read my variable as start-process file path [duplicate]

拜拜、爱过 提交于 2021-01-29 10:12:57
问题 This question already has an answer here : Problems using local variables in a remote commands (1 answer) Closed last year . I'm trying to cleanup my script and I have ran into this issue. When I run Invoke-Command -ComputerName $Computer -ScriptBlock {Start-Process "c:\temp\openVPN\openvpn-install-2.4.8-I602-Win7.exe" I get no issues but when I set a variable so that script looks like this, $filepath = "c:\temp\openVPN\openvpn-install-2.4.8-I602-Win7.exe" Invoke-Command -ComputerName

Enable\Disable Local Group policies with powershell

北城以北 提交于 2021-01-29 10:10:06
问题 I have been trying to enable or disable a Local group policy with powershell to automate the process, I tried installing Remote Server Administration Tools but it's module in powershell needs the pc to be in a domain. Is there any way to enable\disable a Local group policy with powershell? 回答1: Use the registry (note that this requires elevation): Set-ItemProperty -Path <HKLM:RegistryPath> -Name <PropertyToChange> -Value <NewValue> Example (Enabling Search Suggestions from Edge): Set

Renaming text files based on the first word in the file in Powershell

最后都变了- 提交于 2021-01-29 09:32:32
问题 I found many similar examples but not this exact goal. I have a fairly large number of text files that all have a similar first word (clipxx) where xx is a different number in each file. I want to rename each file using the first word in the file. Here is what I have tried using Powershell. I get an error that I cannot call a method on a null valued expression. Get-ChildItem *.avs | ForEach-Object { Rename-Item = Get-Content ($line.Split(" "))[0] } 回答1: I'd do this in three parts: Get the