powershell-2.0

Deleting Gmail Emails via Google API using Powershell v2.0

吃可爱长大的小学妹 提交于 2020-01-11 10:48:48
问题 $user = "example@gmail.com" $pass= "examplepassword" $secpasswd = ConvertTo-SecureString $user -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ($pass, $secpasswd) Invoke-RestMethod 'https://www.googleapis.com/gmail/v1/users/me/messages/0' -Method Delete -Credentials $cred So, my problem here is twofold. I originally tried using Invoke-WebRequest to delete gmail emails via the Google API with a http delete request. However, this did not work because Powershell

Color words in powershell script format-table output

大憨熊 提交于 2020-01-11 05:06:08
问题 Is it possible to color only certain words (not complete lines) for a powershell output using format-table. For example, this script scans a folder recursively for a string and then output the result with format-table. dir -r -i *.* | Select-String $args[0] | format-table -Property @{label="Line #"; Expression={$_.LineNumber}; width=6}, Path, Line -wrap It would be nice to be able to format the word we are searching for with a specific color, so that you can see exactly where it was found on

How can I extract “Path to executable” of all services with PowerShell

随声附和 提交于 2020-01-10 08:03:05
问题 Get-Service *sql* | sort DisplayName | out-file c:/servicelist.txt I have a one line PowerShell script to extract list of all services running on my local machine, now, in addition to displaying "Status", "Name" and "DisplayName" I also want to display "Path to executable" 回答1: I think you'll need to resort to WMI: Get-WmiObject win32_service | ?{$_.Name -like '*sql*'} | select Name, DisplayName, State, PathName Update If you want to perform some manipulation on the selected data, you can use

how to get a pc list that have a service running on each pc?

喜夏-厌秋 提交于 2020-01-08 04:19:09
问题 I m using psexec to auto run from cmd on all PCs on our network to check if certain process is running or not. but i wannt a list with all pc name that has the service running on. how can i do it from powershell? this is what i m running now. 2 batch files and 1 text file. get.bat tasklist | findstr pmill.exe >> dc-01\c$\0001.txt run_get.bat psexec @%1 -u administrator -p password -c "C:\get.bat" pclist.txt what i got from this in result are just all pmill.exe , i m wondering if there is

how to get a pc list that have a service running on each pc?

拥有回忆 提交于 2020-01-08 04:18:49
问题 I m using psexec to auto run from cmd on all PCs on our network to check if certain process is running or not. but i wannt a list with all pc name that has the service running on. how can i do it from powershell? this is what i m running now. 2 batch files and 1 text file. get.bat tasklist | findstr pmill.exe >> dc-01\c$\0001.txt run_get.bat psexec @%1 -u administrator -p password -c "C:\get.bat" pclist.txt what i got from this in result are just all pmill.exe , i m wondering if there is

Best way to detect key combination in windows using built in scripting languages

泄露秘密 提交于 2020-01-07 08:54:49
问题 I was thinking of a scenario to detect a key combination [preferably window key + a] using the built in scripting languages like vb script, powershell script, batch script etc.. is there any way to do this ? 回答1: I personally love AutoHotKey you create a script and it will detect any key combination. It is fast and easy to use and I have dozens of key combinations that I have scripted and use every day. If you must use a built-in scripting language, then the easiest is to create the desired

Best way to detect key combination in windows using built in scripting languages

大城市里の小女人 提交于 2020-01-07 08:53:34
问题 I was thinking of a scenario to detect a key combination [preferably window key + a] using the built in scripting languages like vb script, powershell script, batch script etc.. is there any way to do this ? 回答1: I personally love AutoHotKey you create a script and it will detect any key combination. It is fast and easy to use and I have dozens of key combinations that I have scripted and use every day. If you must use a built-in scripting language, then the easiest is to create the desired

Filter out users that contains a word or character with Get-ADUser

大城市里の小女人 提交于 2020-01-06 15:03:45
问题 I am trying to get a list of AD-Users in different domains but cannot find a way to exclude users that has "Health" in their name for an example. This is how my query looks like as of now: #$excludedusers = @('HealthMailbox123456') Get-ADUser -Server $test -Credential $1cred -Filter{enabled -eq $true} | Where-Object { $_.DistinguishedName -notlike '*OU=.Service Accounts,*' } | Select-object Samaccountname,surname,givenname | Where { $excludedusers -NotContains$_.Samaccountname } As of now,

How to get DatabaseCopies from MailboxDatabase programmatically in C# (wrapped ExchangeMangementShell cmdlets in c#)?

烂漫一生 提交于 2020-01-06 11:01:17
问题 I am wrapping ExchangeManagementShell Cmdlets in C#, to programmatically execute cmdlets (Please refer to __http://social.msdn.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/155504b3-ffe3-4bdf-887a-1e61842a8697) I know the "databasecopies" property of mailboxdatabase contains copies. But i am not sure how to parse the deserilzied databasecopies data to get the properites. Please see the below code snippet. I am basically parsing Get-MailboxDatabase cmdlet results to get the

Invoking C# powershell cmdlets from another powershell cmdlet

泄露秘密 提交于 2020-01-06 08:17:14
问题 Here is my scenario : I have add-data and add-bulkdata cmdlets, both are written in C# deriving from pscmdlet , add-bulkdata takes a csv file and each line is fed to add-data cmdlet. Add-data cmdlet might throw terminating exceptions, if it does I dont know how to receive it in the add-bulkdata cmdlet, in bulkdata cmdlet I get a commandinvocationexception but it does not have the ErrorRecord that the underlying add-data had set. Also if I query pipeline.errors it gives me no information. What