powershell-2.0

Powershell - Run a script located at a remote machine which inturn access files from a network share

梦想与她 提交于 2019-12-02 04:19:53
I'm trying to execute a powershell script located at a remote machine using the below command and it works great invoke-command (powershell c:\install\install.ps1) -computername box1 -credential (get-credential) The above script in-turn copies files from a network share (using robocopy) - It fails complaining the location doesn't exist. Found out it was due to permission issue. It works when I explicitly mentioned in the script to use the following credentials for the share net use \share1\files password /user:username Is there a way to pass in the same credentials used to run the script to be

Conditional replace in XML files

拜拜、爱过 提交于 2019-12-02 04:17:09
I'm replacing a text in XML files recursively using PowerShell. The script is working fine in replacing. However the XML files also have file paths which should not be replaced. This is the script currently being used if ( $content -match ' web site | web-site ' ) { $content -replace ' web site ',' New Site ' -replace ' web-site ',' New Site ' | Out-File $file.FullName -Encoding utf8 For example if the XML file has <title>web site</title> <subtitle>web-site</subtitle> <path>c:/web site/website.xml</path> the expected output is should look like below. The matching text in file paths should be

Sort-Object by greatest numerical value value from Import-CSV

别来无恙 提交于 2019-12-02 03:23:23
I want the greatest value (mailboxSize) at the top of the file. I have a cvs as inport. When I do the following sort cmd: Import-Csv import.csv| Sort-Object MailboxSize,DisplayName -Descending | Export-Csv SORT.csv I get the following result: "DisplayName","MailboxSize" "persone6","9941" "persone3","8484" "persone1","7008" "persone4","4322" "persone5","3106" "persone7","27536" "persone10","24253" "persone8","1961" "persone9","17076" "persone11","17012" "persone2","15351" "persone12","11795" "persone14","1156" "persone13","1008" But I want this as a result! "persone7","27536" "persone10","24253

powershell v2 - how to get process ID

萝らか妹 提交于 2019-12-02 02:58:28
问题 I have an Application, that runs multiple instances of itself. e.g AppName.exe instance1 AppName.exe instance2 AppName.exe instance3 Using Powershell v2 I am trying to create a simple script that given an array of AppNames and instances, it loops through them, checks if they are running, and then shuts them down. I figured the best way to do this would be check for each instance, if found capture it's processID, and pass that to the stop-process cmdlet. BUT, I can't figure out how to get the

Deleting Gmail Emails via Google API using Powershell v2.0

混江龙づ霸主 提交于 2019-12-02 02:39:18
$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 2.0 does not support Invoke-WebRequest . Thereafter, I turned to attempting to utilize Invoke

Sort-Object by greatest numerical value value from Import-CSV

房东的猫 提交于 2019-12-02 01:46:14
问题 I want the greatest value (mailboxSize) at the top of the file. I have a cvs as inport. When I do the following sort cmd: Import-Csv import.csv| Sort-Object MailboxSize,DisplayName -Descending | Export-Csv SORT.csv I get the following result: "DisplayName","MailboxSize" "persone6","9941" "persone3","8484" "persone1","7008" "persone4","4322" "persone5","3106" "persone7","27536" "persone10","24253" "persone8","1961" "persone9","17076" "persone11","17012" "persone2","15351" "persone12","11795"

PowerShell : GetNewClosure() and Cmdlets with validation

落花浮王杯 提交于 2019-12-02 01:22:44
问题 I'm trying to understand how .GetNewClosure() works within the context of a script cmdlet in PowerShell 2. In essence I have a function that returns an object like so: function Get-AnObject { param( [CmdletBinding()] [Parameter(....)] [String[]]$Id .. [ValidateSet('Option1','Option2')] [String[]]$Options ) ... $T = New-Object PSCustomObject -Property @{ ..... } $T | Add-Member -MemberType ScriptProperty -Name ExpensiveScriptProperty -Value { $this | Get-ExpensiveStuff }.GetNewClosure() .. }

Call a BAT in an elevated window and changing ENV variables before

谁说胖子不能爱 提交于 2019-12-02 01:19:50
问题 In a PowerShell script, I have to call a batch file in an elevated window. So I do Start-Process my.bat -Verb runas Now, my.bat expects to have some of the ENV variables I set on the original window. However, since the elevated window is executed as admin, those variables I set as a regular user don't appear to be set on the admin window. Is there a way to set ENV vars in an admin window prior to calling my.bat ? 回答1: What you want isn't possible. For security reasons elevated processes don't

Background job to refresh data on a form while script is running?

让人想犯罪 __ 提交于 2019-12-01 23:02:26
问题 Hope some brave will help me ! I’m working from a few days now on a Powershell tool that display a dashboard on the screen corner to give some network “real-time” diagnostics of the computer. This dashboard can be minimized in the notification area. First, I created a function that get the diagnostics and display the status on the form. I tried to refresh data with a timer (See: Real Time Data With Powershell GUI). The problem was that my function took too much time to be executed and it

how to retrieve memory type ( rdimm or udimm)?

廉价感情. 提交于 2019-12-01 22:28:02
is there a way to know if installed memory is Registered DIMM or Unregistered DIMM ? the win32_physicalMemory doesn't seem to provide this info ? you can find more info about udimm rdimm here EDIT : the solution provided by @C.B doesnt work either The first idea is using WMI Win32_PhysicalMemory and test if TotalWidth (bit count including check bits) is greater than DataWidth (bit count excluding check bits). gwmi Win32_PhysicalMemory | select totalwidth, datawidth, banklabel | % { if ( $_.totalwidth > $_.datawidth ) { "$($_.banklabel) is ECC memory type" } else { "$($_.banklabel) is non-ECC