powershell-3.0

Replace blank characters from a file line by line

天大地大妈咪最大 提交于 2019-12-11 09:46:14
问题 I would like to be able to find all blanks from a CSV file and if a blank character is found on a line then should appear on the screen and I should be asked if I want to keep the entire line which contains that white space or remove it. Let's say the directory is C:\Cr\Powershell\test . In there there is one CSV file abc.csv . Tried doing it like this but in PowerShell ISE the $_.PSObject.Properties isn't recognized. $csv = Import-Csv C:\Cr\Powershell\test\*.csv | Foreach-Object { $_

Rename-Item error: Cannot rename because item does not exist

房东的猫 提交于 2019-12-11 08:43:26
问题 I have the following powershell code, which is attempting to rename all SQL files in a folder, adding a unique prefix to each file e.g. the first prefix will be '1001 - sp - C - ': gci -Path 'C:\FolderToLookIn' -Exclude "1*" | ForEach-Object { New-Object PSObject -Property @{ 'LineNumber' = $linenumber; 'Name' = $_.Name; 'Extension' = $_.Extension }; $linenumber++ } | Where-Object { $_.Extension -eq ".sql" } | Rename-Item -NewName {$_.LineNumber.ToString("1000") + ' - sp - C - ' + $_.Name}

PowerShell $args probleme [duplicate]

非 Y 不嫁゛ 提交于 2019-12-11 07:06:28
问题 This question already has answers here : Is it possible to print variable names? (7 answers) Closed 2 years ago . I try to make this script working Function test_var {$return = 0 foreach ($arg in $args) { if (!$arg) {(Write-Host "ERROR : $arg.Name Missing variable" -ForegroundColor Red -BackgroundColor Black) $return = 1} } return $return } When I call the function with arguments test_var "c" "$b" "$a" The function work correctly but I can't display the name of the actual $arg because the

More-efficient way to modify a CSV file's content

自闭症网瘾萝莉.ら 提交于 2019-12-11 04:58:13
问题 I'm attempting to remove some of the detritus that SSMS 2012 generates when a query's results are exported as CSV. For example, it includes the word 'NULL' for null values and adds milliseconds to datetime values: DATE_COLUMN,DATETIME_COLUMN,TEXT_COLUMN,NUMBER_COLUMN 2015-05-01,2015-05-01 23:00:00.000,LOREM IPSUM,10.3456 NULL,NULL,NULL,0 Unfortunately, Excel doesn't automatically format datetime values with fractional seconds correctly, which lead to confusion amongst the customers ('What

PSCustomobject returrning strange output

一世执手 提交于 2019-12-11 04:29:01
问题 i have a script which is supposed to run a test-connection and a test-netconnection on three servers, for now i'm doing test with "localhost" the thing is i want the it will make at least two times the "test-connection" and it does, but the output is very strange (from the logical point of view is reasonable, but from the output point of view it's not) here is the code: if i use the count parameter and set it to 1 time, the output is correct it shows one pc from which it made the test, if i

How Does Member Enumeration Work in PowerShell 3?

瘦欲@ 提交于 2019-12-11 03:48:46
问题 In PoweShell 2 we did: Get-ChildItem | ForEach-Object {$_.LastWriteTime} | Sort-Object In Powershell 3 we do: (Get-ChildItem).LastWriteTime | Sort-Object But how does it work, i read this blog post on MSDN and they say that its faster because the foreach loop isnt running? So how does it enumerate the properties then ? 回答1: PowerShell is doing the hard work for us and it loops over the collection internally. I like to call this "implicit foreach". Assuming the member you specified is present

Powershell download file from website ie.document method

偶尔善良 提交于 2019-12-11 03:45:36
问题 I have created a little script that log's on to a https website using Internet explore 11. I had a manual mouse click to Download file to IE but im getting the prompt to save open file I would like to be able to bypass this due to im going to run this in the back ground? Am I missing a param on the end of my ie.navigate(url) to just save the file? As I stated above I'm using IE11 for this and downgrading is not an option. Any help would be great $username= get-content -Path c:\username.txt

Powershell Idle Timeout

醉酒当歌 提交于 2019-12-11 03:05:12
问题 I am using the PST Capture Console from Microsoft to import PSTs into Office 365. I use the following to open a session to Office 365. $UserCredential = Get-Credential $Session = -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection This will connect and allow me to start an import and I am able to do small PSTS; however when I try to import large PST files the session times out

Get only computer names from AD

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:48:21
问题 I'm new to Power Shell and I'm testing some commands and ideas. I'm stuck on what I feel should be pretty simple. I want to pull the names of computer objects in AD in to a file. The method I'm trying so far is this $computers = Get-ADComputer -Filter * | Format-List name write($computers) | Out-File -FilePath .\computers.txt the issue I have with this though is that the file that is output looks like this name : SERVER1 name : SERVER2 name : WORKSTATION1 name : WORKSTATION2 And I'm looking

How can I chain Export-CSV to Send-MailMessage without having to save the CSV to disk in PowerShell?

社会主义新天地 提交于 2019-12-11 02:38:18
问题 I would like to email a list of AD users as a CSV but I don't want to have to save the CSV to disk before I email it. Here is the code that gets me the data: get-aduser -filter * -properties Telephonenumber | where Telephonenumber -ne $Null | select givenname, surname, telephonenumber | sort surname Now I want to add on something like: | Export-Csv | Send-MailMessage -From HelpDesk@company.com -to someone@company.com -subject "Outlook address book export" -SmtpServer EdgeTransport Is there