powershell-2.0

Powershell v2: Replace CRLF with LF

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 10:23:23
问题 Using Powershell v2 called from a batch file, I want to replace each CRLF in a file with just an LF. If a file only has LF without any CR, then I want all the LF to be left alone. I do not want a terminating CRLF in the resultant file, if possible. I found this question here on Stack Overflow, that seems to be a close match, but it does not specify a Powershell version requirement, nor does it specify the other criteria above. Hence this question. The accepted answer for that question

Powershell datagridview cell click event

我是研究僧i 提交于 2019-12-08 09:45:29
问题 I have a powershell script in that script i am using datagridview. My script is working fine. All looks ok to me. My issue is i want to get the first column value of selected row. To fulfill this i need to add event (cell click/cell content click/cell mouse click). I am not able to figure it out. How to add event. Can somebody please advise me on this? $datagridview1_CellMouseClick = [System.Windows.Forms.DataGridViewCellEventHandler]{ write-host $_.RowIndex # This displays the row number

Creating a PowerShell Connection String

ぃ、小莉子 提交于 2019-12-08 08:59:39
问题 I have been trying to create a ConnnectionString that will allow me to connect to my local database using PowerShell. Below is my code: $conn = New-Object System.Data.SqlClient.SqlConnection $conn.ConnectionString = "Server=localhost;Database=test;Uid=<username here>;Pwd=<password here>;" $conn.Open() $sql = "SELECT EMP_STATUS FROM test_table" $cmd = New-Object System.Data.SqlClient.SqlCommand($sql,$conn) $rdr = $cmd.ExecuteReader() while($rdr.Read()) { $test = $rdr["EMP_STATUS"].ToString() }

I need to delete users from Active Directory using a imported csv file

末鹿安然 提交于 2019-12-08 07:32:41
问题 I have a CSV file with a list of user names, I need to delete all of these users from Active Directory using the Remove-ADObject command . I am not very familiar with the syntax for this command - hoping you guys can help me here. Import-Module activedirectory $list = Import-CSV C:\Users\user\Desktop\deleteuserstest.csv forEach ($item in $list) { $samAccountName = $item.samAccountName Remove-ADobject -Identity $samAccountName } 回答1: You have to use DN or GUID with Remove-ADObject. You can do

Powershell - Add SSL binding using shared certificate

社会主义新天地 提交于 2019-12-08 03:05:47
问题 I am using following code to link certificate to SSL binding that I have added $thumb = (Get-ChildItem cert:\LocalMachine\My | where-object { $_.Subject -like $wildCardSubject } | Select-Object -First 1).Thumbprint Push-Location IIS:\SslBindings Get-Item cert:\LocalMachine\My\$thumb | New-Item $ipAddress!$port Pop-Location This works fine without any errors. After running this, if I open bindings UI for that website from IIS manager I do not see any certificate attached to the binding. Am I

Keep x number of files and delete all others - PART TWO

 ̄綄美尐妖づ 提交于 2019-12-08 02:53:30
问题 I asked a question earlier about how to go through a directory structure and keep the 7 most recent copies of a file in each sub directory. The script below is what was created and it works great but only on 1 directory. I need to to go through the entire directory and keep the 7 newest files in each sub directory. To test I created a directory structure under C:\Customer with sub directories of Test1, Test2, Test3. I then created 12 test files in each directory including the top level C:

Powershell to do Clearcase checkin ,checkout,find command?

强颜欢笑 提交于 2019-12-08 02:28:00
问题 How to do check-in /check-out /Find and etc operation in Clearcase UCM using powershell. Is there any way custom cmd-lets are available for this? 回答1: For more advanced functionality and better response times, I'd recommend accessing the CAL API directly via COM. The best documentation for that is available locally in <ClearCase install dir>\bin\cc_cal.chm . $cc = New-Object -COM ClearCase.Application $ccItem = $cc.Version("<absolute path to file/dir>") $coItem = $ccItem.CheckOut($cc

File in use with .net method but not with powershell cmdlet

和自甴很熟 提交于 2019-12-07 21:55:11
问题 To open and read files in powershell I use one of two methods: Get-Content $path or [System.IO.File]::OpenRead($path) While reading a log file that is in use by another process Get-Content doesn't seem to have any issues with it. Then again the powershell cmdlet is slow and uses more memory compared to .NET method. When I try to use .NET method however, I get the following error: "The process cannot access the file 'XYZ' because it is being used by another process." Q1: Why can't .net method

Speed up PowerShell script for Windows Registry search (currently 30 minutes)

天涯浪子 提交于 2019-12-07 19:01:21
问题 I'm working on a script for use in Windows 7 and Windows 10 for a Windows Registry search in HKLM:\Software\Classes. So far my code works, but it's extremely slow. It takes about 30 minutes to complete. I need to use Set-Location also to avoid an error with Get-ItemProperty, which occurs because the $path is not a valid object. How can I speed this code up? What's wrong? File regsearch.ps1 (Mathias R. Jessen's answer applied) Function Get-RegItems { Param( [Parameter(Mandatory=$true)] [string

How to set LastWriteTime property of a file?

99封情书 提交于 2019-12-07 12:51:54
问题 I would like to change the creation date of the files that I generate with this script : $clientname = Read-Host "Enter the client name" $path = Read-Host "Enter the complete path of .bak files" $time = "01-00-00" $space = " " for ($i = 0; $i -lt 7;$i++) { $date = (Get-Date).AddDays(-1-$i).ToString('yyyy-MM-dd') New-Item -ItemType file $path$clientname$space$date$space$time.bak } So it gives me theses files : Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 16/08/2013 16:55