powershell,select,format , Get-PSDrive select formatting


Get-PSDrive select formatting

Question:

Tag: powershell,select,format

I'm trying to do simple select formatting in powershell with gdr ( Get-PSDrive ), namely:

When you exec gdr with no parameters, you receive statistics in GB

PS > gdr

Name           Used (GB)     Free (GB) 
C                 187.31        278.10 

How do I select the colums in GB -"Used (GB)", , without it converting it to bytes ?

gdr -PSProvider filesystem | select Name, Used

Name     Used
----     ----
C       201127354368

I don't want to further convert it @{Used="} style, I need to just "select column the way it is " :)

Thanks,


Answer:

Use a calculated property.

get-psdrive -psprovider FileSystem |
  select-object Name,@{Name="Used" Expression={$_.Used/1GB}}

See help for Select-Object.


Related:


Get IP address of the Network Adapter of a computer having No gateway


powershell,ip-address,gateway
I've a project to add persistent routes on a list of servers which I need to do through Powershell. Our environment has 2 NIC's for every server , one production one backup. For this I need to fetch the Backup IP address of the computer , replace the last octet...

Send email with body consisting of objects


email,powershell,foreach
I am trying to write a script to search through AD and look for any stale computers and then sends an email to me. However, there are 3 requirements: get the lastlogondate for any pc that is older than 90 days once I get that list, I do a ping...

PHP - Find File in Directory By File Name [closed]


php,select,directory,filenames
I have a directory full of filenames that contain unix timestamps. file_1434320602.data file_1434320352.data file_1434320112.data file_1434320032.data How would I get about loading them up in PHP so that I can select the one which I needed?...

PowerShell logic to remove objects from Array


arrays,powershell
I'm trying to remove objects from an array that contain duplicates and only keep the ones with the highest number in TasteCode. The example below is highly simplified, but it shows the problem. Example: $Fruits Name | Color | TasteCode ----- ------ --------- Apple | Red | 2 Apple |...

Programmatically accessing TFS history [closed]


c#,.net,powershell,tfs
I have a solution under TFS source control and had written some sample code using an external library that was deleted a few months ago. I am certain that the code was checked in before that class file was deleted. I am able to manually browse to previous versions of...

Pandas DataFrame: Delete specific date in all leap years


python,select,pandas,leap-year
The following sequence is an extract of the pandas DataFrame that I've got: >>> df_t value 2011-01-31 -5.575000 2011-03-31 7.700000 2011-05-31 15.966667 2011-07-31 10.683333 2011-08-31 10.454167 2011-10-31 9.320833 2011-12-31 -0.358333 2012-01-31 -11.550000 2012-03-31 1.700000 2012-05-31 12.333333 2012-07-31 12.816667 2012-08-31 11.837500 2012-10-31 2.733333 2012-12-31 4.075000 2013-01-31 2.450000 2013-03-31 -4.262500 2013-05-31 11.491667...

Knokout select : Set Selected Item by item name not value


jquery,select,knockout.js
i have a knockout select as following observable Array issuingCountries 0: ObjectCoordinatorRegion: "EU" Country: "Australia" CountryId: 14 Id: 1 2: ObjectCoordinatorRegion: "AU" Country: "Japan" CountryId: 16 Id: 2 html <select class="issuing_country" data-bind="options: issuingCountries, optionsText : 'Country', value:IssuingcountrySelected, optionsCaption:'---Select---', " > </select> My question , i have { Country: "Japan" }...

Define an array with prefixes using the range operator


arrays,powershell
From this I can see I can do this with range operator: $myArray = @(4..9) But how can I do something like this: $myArray = @(usr4..9) I have tried various deviations of this with nonsense errors: $myArray = 4..9 | %\{ "usr$_"\} ...

Get list of files whose creation date is greater than some date time


powershell,windows-server-2012
I have a date 2015/05/28 I want to list all files using order by creation date whose creation date is greater than that using PowerShell. How could I do that? I googled for it and found Get-ChildItem "C:\Users\gerhardl\Documents\My Received Files" but no idea how to compare it with creation date...

Using Sum in If in Mysql


mysql,sql,select,sum
I want to select the sum of values of my_field. The unit of my_field is in seconds. I don't want to exceed 24 hours, so when it exceeds 24 hours, I want it to select 24*60*60 = 86400. SELECT IF(SUM(my_field) > 86400, 86400, SUM(my_field)) ... This solution doesn't seem to...

Combining two select statements


sql,database,select,where
I have two statements as such: var chgAssociationQuery1 = (from a in sostenuto.PROBLEMS join b in sostenuto.S_ASSOCIATION on a.SERVICEREQNO equals b.FROMSERVICEREQNO join c in sostenuto.Changes on b.TOSERVICEREQNO equals c.SERVICEREQNO where b.FROMSERVICEID == 101001110 && b.TOSERVICEID == 101001109 && a.NAME.Contains(name) select new { ProblemReqNo = a.SERVICEREQNO, ProblemId = a.SERVICEREQID, ChangeReqNo =...

CPU usage missing from log for some processes


powershell
I'm trying to get information on all processes and services and save it into a .log. Here my Problem: Some processes have noting inside the CPU table, there I want to add something like "Nothing". How can I achieve that? That is my code so far: $ProcessTable = @{Expression={$_.ProcessName};Label="ProcessName";Width=40}, @{Expression={$_.CPU};Label="CPU";Width=20}...

Color a cell on the basis of another cell value


html,powershell,powershell-v2.0
I have a file output.txt having below content: SERVER_NAME MOUNT_POINT TOTAL_SPACE USED_SPACE USED_PERCENTAGE AVAILABLE_SPACE Server_1 /dev 1200G 537G 54% 464G Server_2 /dev 600G 490G 85% 94G Server_3 /dev 600G 402G 69% 181G Backup_server /storage 800G 682G 72% 278G Using following script, I formatted my output.txt file to get a notification...

PS pipe WorkingSet as variable


variables,powershell
I have this which gives me the WorkingSet memory usage I'm after: $mem=Get-Process spiceworks | Select-Object Name,@{Name='WorkingSet';Expression={($_.WorkingSet/1KB)}} But I'm looking to only have the actual amount as the variable so I can then work with that to monitor it. I want to set it so it alerts me if it...

QUERY IN C# ,where statement


c#,.net,select
How can I write this query on c# : SELECT DEPT_ID FROM PERSONNEL_TEMP.DEPARTMENT WHERE DEPARTMENT_NAME=combobox1.text; ...

python - how to check whether some given date exists in netcdf file


python,date,select,netcdf
I read my timesteps from a netcdf file: timesteps = ncfile.variables['time'] Now I would like to know whether some given date (say, June 23th) exists in that list. If it does, I want to omit it. The netcdf file contains arbitrary dates. I have no clue how to do this...

PHP: How to push Select results to multi-dimensional array (partially working)


php,arrays,loops,select,multidimensional-array
I am new to PHP and hope someone can help me with this. I have a Select query that returns (among others) the values from two columns in a db table, "ID" and "en". When getting the results from the Select I would like to store both these values for...

SQL Oracle | How would I select a substring where it begins with a certain letter and ends with a certain symbol?


sql,oracle,select,substring
If I had this: NAME EYES==ID==HAIR Jon Brown==F9182==Red May Blue==F10100==Brown Bill Hazel/Green==F123==Brown ...and I wanted to create a new ID column with the ID alone, and I know that everyone's ID starts with an 'F' and will end at the '=' how would I select a substring from the compact...

How can I find get attribute of a select tag where value = something using jquery?


jquery,select,drop-down-menu,html-select
How can I get the price attribute's value where #products.option value = 6. <select id="products"> <option value="2" price="60.00">Product 1</option> <option value="4" price="40.00">Product 2</option> <option value="6" price="40.00">Product 2</option> <option value="8" price="40.00">Product 2</option> </select> ...

Dynamically select from a dynamically generated dropdown


php,html,select,drop-down-menu
I have a dynamically generated dropdown list - list of course identifiers and names. On the basis of a variable, “assigned_course_id”, I would like to preselect the appropriate value from the dropdown list. My best attempt is as follows. Thanks in advance for your assistance. <select name="course_id" id="course_id"> <?php $assigned_course_id...

Powershell Reading text file


powershell,text,text-files
I'm just wondering if it's possible to read the content of text file with specific index? What I mean is like this, for example: I have text file like this, 'test1.txt' 12345678900 ## ## readthistext 54321123440 ## ## hellothistext I just want to read the content of text file after...

In a MySQL select statement, can I split a text column and then sum the parts as floats?


mysql,select,casting,split
I have a MySQL column that is defined as text. The column, if not null, always contains a list floats separated by a newline character. I have been tasked with making the total amount of those floats searchable with min and max constraints. In the where clause, I would like...

SELECT * FROM WHERE Query isn't retrieving any results


mysql,select,mysqli,fetch
I'm using a SELECT * FROM "" WHERE "" = "" query and I'm not sure what I'm doing wrong with it. I'm trying to select an item based on its PO which is a completely unique identifier to one row in the table. Here's my process in doing so:...

PHP: While loop not working after adjusting SELECT for SQL injection prevention


php,mysql,select,sql-injection,associative-array
I am trying to set up PHP queries for MySQL in a way to prevent SQL injection (standard website). I had a couple of INSERT queries where changing this worked well but on the following SELECT I keep getting an error since the update and it looks like the while...

What is the `.` shorthand for in a PowerShell pipeline?


powershell
I'm looking over a block of code I've used (sourced from another question) and I haven't been able to figure out what the . in .{process represents in this snippet (comments removed): Get-ItemProperty $path | .{process{ if ($_.DisplayName -and $_.UninstallString) { $_ } }} | Select-Object DisplayName, Publisher, InstallDate, DisplayVersion,...

Join SQL query Results and Get-ChildItem Results


sql-server,sql-server-2008,powershell
Background: I have a directory with a number of files that are imported to SQL server. Task: Creating a PowerShell script which will pick up files within this directory and use the filenames as in the SQL query. Ultimate objective: To display SQL results besides the filenames but the resultset...

Codeigniter Select JSON, Insert JSON


json,codeigniter,select,insert,routing
I have very simple users database: user_id, user_name, user_email My model this: class Users extends CI_Model { private $table; private $table_fields; private $table_fields_join; function __construct() { parent::__construct(); $this->table = 'users'; $this->table_fields = array( $this->table.'.user_id', $this->table.'.user_name', $this->table.'.user_email' ); $this->table_fields_join = array(); } function select(){ $this->db->select(implode(', ', array_merge($this->table_fields, $this->table_fields_join)));...

How do I select a string from a string and replace it in powershell?


powershell
I'm trying to write a powershell instance that finds and replaces each instance of text and replaces it. UserRights "rights_wo_view" I need to place parenthesis around the quotes. I've been trying all kinds of things, but I'm running flat. $files = get-item C:\Users\programmer\Documents\Project\tsbrick\*.asp foreach ($file in $files) {(Get-Content $file) select-string...

Search for certain UPN suffix


powershell,active-directory
How do I search AD users by UPN suffix in AD? The users are under Uofguelph/SEC213/users OU. Some users have @sec213.com suffix and some have @home.sec213.com suffix. I need to search for users who only have @sec213.com suffix. I have the following two code snippets. Code 1 gets all accounts...

How to create a powershell script that triggers a NuGet Update-Package –reinstall?


powershell,nuget-package
I have a nuget spec that installs both library file (dll) and two zip packages on a specific folder. Updating the packages is no issue when doing it from Visual Studio 2013 manually. However, when it is being triggered from either our CI servers TeamCity and CCNet, it is only...

How do I write a loop to read text file and insert it to the database


sql-server,loops,powershell
I'm writing a powershell script to load text files from a specific folder into SQL server database, I have manage to do so but only one file by one file. I want the program to do this automatically once the user inputs the path and the file extension. For example:...

Powershell workflow - Get-Service not filtering


powershell,workflow
I am trying to restart Windows services in parallel via Powershell workflow. When I use Get-Service -DisplayName "S*" outside of workflow I get expected results. However, when I use the same in workflow, I get ALL services instead. It seems that -Displayname parameter is ignored in workflow. How do I...

Remove all folders .old


powershell
I'm trying to delete all folders in \\kiewitplaza\vdi\Appsense_profiles that end with .old. The piece I have that says Write-Host $name is just me trying to test before I delete anything. $name = Get-ChildItem "\\kiewitplaza\vdi\Appsense_profiles" if ($name.name.EndsWith(".old")) { Write-Host $name #Remove-Item "\\kiewitplaza\vdi\Appsense_profiles\$name.old" } ...

Filter and delete Registry values with Where-Object


powershell,registry
I'm not sure why I'm finding this so difficult. From under a particular registry key, I'd like to query certain registry-values based on their data (not name), and delete the resulting registry-values. For example: How would I delete any values in this key that contain, let's say, "foo". I can...

PowerShell - Convert CSV to XLSX


powershell
I found this script on here, please help me understand this better. What is the whole "gps" part of the script for? What part of this script is overwriting my original CSV and copying in the PC's taskmanager list? Processes. What does this do, why 51? ($xlOut,51) I went searching...

How to retrieve the name and path of VM's through powercli


powershell
am using the below script to retrieve the NAME and PATH of the VM's and in the PATH am getting the full length path which i dont want it, i just need the path which is displaying after the Resources in the output here is my code: function Get-Path{ param($Object)...

Groovy: run SQL SELECT LIKE from file with params


sql,select,groovy
The groovy code is import groovy.sql.* dbUrl = 'jdbc:sqlserver://server' dbUser = 'username' dbPassword = 'password' dbDriver = 'com.microsoft.sqlserver.jdbc.SQLServerDriver' sql = Sql.newInstance(dbUrl, dbUser, dbPassword, dbDriver) def sqlfromfile = new SqlFromFile() sqlfromfile.sql_filename='select_query.sql' sqlfromfile.read() try{ def result = sql.rows(sqlfromfile.result,[id:'01']) println result }catch(e){ println e } class SqlFromFile { def sql_filename def read(){ result=...

Selecting and removing a html select option without selecting by index or ID, using vanilla JavaScript


javascript,function,select,options
I need to remove an option on a select box, and I've figured out a potential solution in the code below, but it doesn't feel particularly 'safe' (if another developer decided to add an option to the backend, the option will re-appear). Is there a better way of achieving this...

Why doesn't “go get gopkg.in/…” work while “go get github.com/…” OK?


windows,git,powershell,github,go
I try to use go get gopkg.in/fatih/pool.v2 to install pool according to Readme.md, but can't success: C:\Users\xiaona\Documents\GitHub> go get -v gopkg.in/fatih/pool.v2 Fetching https://gopkg.in/fatih/pool.v2?go-get=1 https fetch failed. Fetching http://gopkg.in/fatih/pool.v2?go-get=1 import "gopkg.in/fatih/pool.v2": http/https fetch: Get http://gopkg.in/fatih/poo l.v2?go-get=1: dial tcp 107.178.216.236:80: ConnectEx tcp: A connection attempt failed because the connected party did not...

Post messages from async threads to main thread in F#


.net,powershell,f#,system.reactive,f#-async
There is a subscription to an observable that sends out log messages. Some of the log messages come from other threads because they are are in F# async blocks. I need to be able to write out the messages from the main thread. Here is the code that currently filters...

Format a command in powershell including a comma, can't find the right way to escape


powershell,batch-file,escaping,powershell-v2.0,comma
I have a command that I need to run in a Powershell script, the command is : ".\pacli DELETEUSER DESTUSER='"[email protected]`,com"' sessionid=333" | invoke-expression The comma (,) in here :[email protected],com is not a mistake, and that's what is giving me the hard time. I tried to escape the comma with `...

Increment Serial Number using EXIF


windows,powershell,command-line,exif,exiftool
I am using ExifTool to change the camera body serial number to be a unique serial number for each image in a group of images numbering several hundred. The camera body serial number is being used as a second place, in addition to where the serial number for the image...

Extract e-mail from grouped objects


powershell
I have some code that pull user accounts from an OU in AD. I am sorting it using Group-Object so I know how many users are using the same email address. Code below, the $OuUser uses Get-ADUser with Properties and Filter set to *. $Duplicates = $OUUser | Select samaccountname,...

Loop Issue - Remote Server


powershell
I wrote a small script to get some basic information off a few remote servers. But my output it is a bit odd. I believe my issue is with my $DRIVE function. Code: $serversList = 'svr01.xxx.com', 'svr03.xxx.com', 'svr05.xxx.com', 'svr06.xxx.com', 'svr08.xxx.com' #End of Server List Write-Output "Start of Hal0 `n"; ForEach...

how select a dynamic id generated in php with jquery


jquery,select
this code generated in php id="sus- ... <--- is static and id="sus-d->id ?>" is my problem to select that <button class="btn btn-danger btn-xs" id="sus-<?= $D->d->id ?>" ><i class="icon-trash "></i></button> out put : id="sus-2131" so i want select all id's start with sus- with below function : jQuery('#sus-').btsConfirmButton({msg:"I'm sure!"}, function(e) {...

display number of elements depending on option selected


javascript,jquery,select,options
I'm trying to add a 3rd filter to track/display the number of elements shown depending on the option selected (#filter9). This is what I have so far, I got the code from: Filter based on combination of multiple select and single select elements. This is what i'm trying to edit:...

How to create a SELECT query FROM “TABLE1 AND TABLE2”


sql,postgresql,select,join
I have a PostgreSQL database, with only SELECT permissions. In this DB there are two tables with the same structure (the same columns). I need to write several query in each table and join the results. There is a way for writing a query like this one? SELECT field1, field2,...

Using --check on a md5sum command generated checksum file is failing


powershell,cygwin,md5sum
I'm encountering an error when I try and run md5sum -c on a checksum file I generated. I should mention that I'm running this from PowerShell (as a script will be running this eventually) and this is the cygwin version of md5sum. I have a test file, jira_defect.txt and I've...

PowerShell XML formatting issue


xml,powershell
I'm having trouble getting a properly formatted XML file using the following code: # Get Computer System info $CompInfo = Get-WmiObject Win32_ComputerSystem $CompName = $CompInfo.Name # Get IP Address $IPAddressTemp = Test-Connection $CompName -count 1 | select Address,Ipv4Address $IPAddress = $IPAddressTemp.IPV4Address # Begin Writing values to XML Document $filePath =...

Why does piping Get-PSSession to Exit-PSSession not work?


powershell
I'm creating a new Powershell session like so: New-PSSession -ConnectionUri https://myserver:12345 -Credential myserver\username -Authentication default This is working fine, I can do Get-PSSession and it provides me with that one session. However, when trying to pipe the result to Exit-PSSession things go haywire. So this: Get-PSSession | Exit-PSSession Or this:...