powershell-2.0

get specific cell value in csv file using powershell

人走茶凉 提交于 2019-12-14 03:08:13
问题 I am new to powershell, don't get to use this often. I need to output the value of cell A5 from a csv file using powershell my file - col1 col2 col3 col4 ---- ---- ---- ---- 1002 1005 1006 1007 need value in the A1 cell i.e 1002.selection should be done by the cell numbers. $a = @(Import-CSV filepath.csv) $a[1].(col1) thanks in advance 回答1: Import the CSV to your variable $a = Import-CSV filepath.csv Then grab the first row $a[0] and use . notation to get the column you want. Note that the

Powershell - verify object exists in AD

て烟熏妆下的殇ゞ 提交于 2019-12-14 01:50:55
问题 i have a text file containing arround 100 servers, how can i push these into a script and test if they exist within AD? I have a simple script below: $serverlist = get-content ServerList.txt foreach ($server in $serverlist) { if (Get-ADComputer $serverlist ) { Write-Host "#########################" Write-Host "Computer object exists" Write-Host "#########################" } else { Write-Host "#########################" Write-Host "Computer object NOT FOUND" Write-Host "#######################

String Matches to Datatable

拜拜、爱过 提交于 2019-12-13 20:51:12
问题 I need to extract several pieces of information from a line of text that contains a certain key value. It seems like this would be a fairly common scenario, but I haven't been able to find much info that helps. Currently I am using select-string to find all lines that contain either "242200" or "242201". Once these lines are identified I am trying to extract parts of the line and put them into a datatable. I then need to sum two columns of the DT and export the result as CSV. This is what I

How to search a word in a file using PowerShell script

大城市里の小女人 提交于 2019-12-13 20:05:13
问题 I have a list of 350 folders and each folder has a file Access log. I need to search all 350 files under all 350 folders for a name "Hound" and display the name of the folders which contain the name "Hound" in their access log file. Below is my code, can someone help me with what should be added here to get the desired output, please? #List all the folders in C:\testfolder $folders = (Get-ChildItem -Path "C:\testfolder" | Where-Object{$_.Attributes -eq "Directory"} | Select Fullname) #looping

Get Solr Cores via Powershell

女生的网名这么多〃 提交于 2019-12-13 17:16:23
问题 Is there a way to use Powershell to get a list of Solr cores running in my local instance of Solr? I am running Solr 4.10.1, and am using Powershell 2.0. I would like to create a text file of core names: somecore1 somecore2 etc. I was able to get a list of my cores in XML format by hitting this URL: http://localhost:8983/solr/admin/cores The pertinent details of the return XML are: <response> <lst name="responseHeader"> <int name="status">0</int> <int name="QTime">2663</int> </lst> <str name=

Error creating Outlook Rules in Powershell

点点圈 提交于 2019-12-13 14:46:25
问题 I've been messing around with Outlook objects for Powershell. I wanted to create Outlook Rules and I got it to work. Layed the project aside for a while. When I picked it back up I was unable to create Outlook rules. Note that I did NOT change anything in the code. Code generating Outlook Rule $rules = $ol.Session.DefaultStore.GetRules() $rule = $rules.Create("spamfilter",[Microsoft.Office.Interop.Outlook.OlRule Type]::olRuleReceive) $condition = $rule.Conditions.SenderAddress $condition

How can I append files using export-csv for PowerShell 2?

╄→гoц情女王★ 提交于 2019-12-13 12:28:37
问题 $filesremoved | export-csv -Path E:\Code\powershell\logs\filesremoved.txt -NoTypeInformation I've also tried $filesremoved | export-csv -Path E:\Code\powershell\logs\filesremoved.txt -NoTypeInformation -NoClobber The file appears to be overwritten every time. Is there a way to keep adding content to the file? I get errors Export-Csv : A parameter cannot be found that matches parameter name 'Append'. 回答1: The -Append parameter of Export-Csv doesn't exist until PowerShell 3.0. One way to work

if script runs true restart/run next part

Deadly 提交于 2019-12-13 08:59:19
问题 I'm trying to get the script to restart the computer when the script returns $true, I'm planning to run the script in SCCM or task scheduler. I was going to get the SCCM to restart the computer if it returns $true but don't know how to so now I'm trying to add a restart within the script itself but don't know how to add it correctly . function Test-PendingReboot { if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return

How to execute powershell script in 64 bit machine?

廉价感情. 提交于 2019-12-13 08:45:55
问题 I have written a powershell script and send to my team mates. One of my teammate when he was right click and [Run with powershell] execute the script it did not work. He told that it is Win7 64 bit machine. Then i manually opened 32 bit Powershell and use the " Powershell -file <Filename> " and executed. In 64 bit environment, can't we simply execute by right click and Run with powershell? 回答1: If for some reason your script can run only in x86 architecture add this at start in your script:

How to access a network shared drive inside Invoke-command

馋奶兔 提交于 2019-12-13 08:06:51
问题 I was using below script to copy files from network share to local drive. But,I was not able to access path and getting Path not found error. MY use case is I need to execute this script from Jenkins server and remote into server1 and then have copy files from shared directory (\server2\QlikView) which is already mounted to the server1 as S:\ drive. I was able to access this shared path from powershell If I run the command from server1.But, not inside Invoke-Command script block as shown. Any