powershell-2.0

AES encryption on files using PowerShell

扶醉桌前 提交于 2019-12-11 10:36:59
问题 I was able to AES encrypt files successfully using this script here, using Windows 10, PowerShell version 5.1. When I tried running it on Windows 7, PowerShell v2.0, I get an error: New-CryptographyKey : You cannot call a method on a null-valued expression. At C:\Users\IEUser\Desktop\enc.ps1:399 char:27 + $key = New-CryptographyKey <<<< -AsPlainText + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException

Find Replace Text in a File Name - Powershell

元气小坏坏 提交于 2019-12-11 09:58:59
问题 i have a need to replace different string in file names. Is there a way to modify a file name using a find replace function in Powershell? I have done this in a .bat file but would for this to be done in PS instead. 回答1: You didn't provide any details so here's a generic example: $pattern = "foo" # Getting all files that match $pattern in a folder. # Add '-Recurse' switch to include files in subfolders. $search_results = Get-ChildItem -Path "C:\folder" ` | Where-Object { ((! $_.PSIsContainer)

Powershell “Start-process” not running as scheduled task

∥☆過路亽.° 提交于 2019-12-11 09:34:06
问题 Have two powershell scripts that I edited from XP to run in Win Server 2k8 R2. They run fine when executed by manually in powershell, but if scheduled and run as domain admin, they perform all file operations they're supposed to; except they don't do a start-process that sends the file to the SFTP site it needs to go to. They're launched by running powershell.exe with arguments as such: -noprofile -ExecutionPolicy Bypass -file C:\Users\administrator\Documents\script1.ps1 Again, like I

getting login to SQL Server 2005 with invalid credentials

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 08:29:49
问题 The purpose of script is to log into a remote SQLSERVER and execute a query. I used the below code to to ask for credentials and when the connection is open i will check using $conn.state , when its open i have to execute queries. Even when i give invalid credentials, the control is going into Switch --> Open block and getting the statement out Logged in.The connection is Open . clear $servername = "Someserver";$databasename = "someDB";$c = Get-Credential $connectionString = [string]::Format(

How to set a value for MSBuild property using PowerShell

蹲街弑〆低调 提交于 2019-12-11 08:18:52
问题 I have a property to specify the build drive: <PropertyGroup> <BuildDrive Condition="'$(BuildDrive)'==''">Y:</Group> </PropertyGroup> If I want to change the build drive using a batch file, I can do as follows: @echo off set buildDrive=H: :: Then call MSBuild Msbuild /t:BuildTarget %Projectfile% %Logger% Now I want achieve the same using PowerShell. I tried as follows in my PowerShell script, build.ps1: $BuildDrive=H: MSbuild /t:BuildTarget $ProjectFile $Logger But it is not honoring the

Regex and ignore whitespace

允我心安 提交于 2019-12-11 08:13:27
问题 I have the following regex that I am using to match on various credit card numbers within a string search of files. However, if there is a space before or after the pattern to match, then the match will fail. $CC_Regex = "^(\d{4}-){3}\d{4}$|^(\d{4} ){3}\d{4}$|^\d{16}$" For example, it will match the top three, but will not match the bottom three. 1111-2323-2312-3434 1234343425262837 1111 2323 2312 3434 1111-2323-2312-3434 1234343425262837 1111 2323 2312 3434 Out of the bottom three, the first

How to insert a soft hyphen

佐手、 提交于 2019-12-11 07:35:58
问题 I would like to insert a soft hyphen between every letter in a word using powershell. for example here is some text: Thisisatest => T-h-i-s-i-s-a-t-e-s-t - is a soft hyphen. How might i do this in powershell? 回答1: Using .NET methods a little more than canonical PowerShell code, you can write $word = "Thisisatest" [System.String]::Join("-", $word.ToCharArray()) and Powershell outputs "T-h-i-s-i-s-a-t-e-s-t" EDIT: For a true soft hyphen, and using this answer on Unicode in PowerShell, I would

PowerShell CRUD with WCF Data Services (OData)?

北慕城南 提交于 2019-12-11 07:07:00
问题 I am trying to perform CRUD against WCF Data Services (OData). The Read portion is pretty well documented across the web… it’s the Create, Update and Delete that I am having trouble with. 回答1: As for the documentation, have you looked at odata.org: http://www.odata.org/developers/protocols/operations#CreatingnewEntries It has a description and samples of all the common CRUD operations against an OData services. You can also write a sample client application using any OData client (for example

Passing Powershell Get-ChildItem filter parameter through a string variable is not working

岁酱吖の 提交于 2019-12-11 06:15:31
问题 In my script I have below function that returns a string as "*.csproj", "*.vbproj", "*.sln". Assuming I always pass a string such as "csproj, vbproj, sln" to $filter parameter: Function Create-Filter($filter) { $str = $filter.Split(',') | ForEach-Object {"""*.$($_.Trim())"""} $str = $str -join ', ' [string]$str return } Later in my script I perform: $filter = Create-Filter($filter) $myFiles = Get-ChildItem $source -Include $filter -Recurse But $myFiles is empty, Get-ChildItem is not returning

Sending Formatted HTML email

纵饮孤独 提交于 2019-12-11 05:37:28
问题 I have a text file output.txt which has following content: OPERATINGSYSTEM PROJECTSERVER1 PROJECTSERVER2 Windows 1.36 4.42 Linux12 2.78 5.76 MacOS 3.45 6.39 Ubuntu 4.12 0.00 Android 0.00 3.46 FreePhysicalMemory 30.12 31.65 TotalVisibleMemorySize 48.00 48.00 CPULoadPercentage 2 4 I want to send content of output.txt in a email as a body in Formatted HTML table look in Windows server 2008 R2 . I am trying with below code, but its not working for me..where am I mistaking below ? $smtpServer =