powershell-2.0

Calling Powershell from C# (ASP.NET) - pass custom object?

大憨熊 提交于 2019-12-10 12:13:58
问题 I'm having trouble trying to call a Powershell function from C#. Specifically, I'm getting stuck trying to pass a generic list of Project's to a powershell module function. Here is the code: var script = @". \\server01\Modules\Runspace.ps1; Get-MyCommand"; var allProjects = _pmRepository.GetAllProjects(); using (Runspace runSpace = RunspaceFactory.CreateRunspace()) { runSpace.Open(); PowerShell posh = PowerShell.Create(); posh.Runspace = runSpace; posh.AddScript(script); posh.AddArgument

Apply service packs (.msu file) update using powershell scripts on local server

半世苍凉 提交于 2019-12-10 11:29:52
问题 What it basically does is the script gets the .msu files from a location and copies to the "C:\temp\" folder. Then the script gets all the .msu files and stores the names in the array. Using the foreach loop it tries to apply the .msu updates to the local server where the script is running. However when i run the script. It doesn't do anything. Below is the code $from="sourceLocation\*.msu" $to="C:\temp\" Copy-Item $from $to -Recurse -Force $listOfMSUs= (Get-ChildItem –Path $to -Filter "*.msu

Using special characters (slash) in FTP credentials with WebClient

橙三吉。 提交于 2019-12-10 11:28:58
问题 EDIT: I have discovered it's definitely the password that is causing issues. I have a forward slash in my password and cannot figure out how to get this to accept it. I've already tried replacing it with %5B . Changing the password is not a possibility. cd v: $username = "*********" $password = "*********" $usrpass = $username + ":" + $password $webclient = New-Object -TypeName System.Net.WebClient function ftp-test { if (Test-Path v:\*.204) { $files = Get-ChildItem v:\ -name -Include *.204 |

Log file not being generated while running a script via Windows Task Scheduler

淺唱寂寞╮ 提交于 2019-12-10 11:17:54
问题 Log file not being generated while running a PowerShell script via Windows Task Scheduler. Code as below: function check-cert { $cmd = "Certutil -crl" Invoke-Expression $cmd if($LASTEXITCODE -eq '0') { Write-Output $LASTEXITCODE } else { $output = $LASTEXITCODE $date = (Get-Date).ToString() $result = $date + " " + $output $result | Out-File "C:\users\admin\Documents\Powershell\crllog.txt" -Append Write-Host "crl failed to publish" } } check-cert Could you please help me in getting the log

Is there way to know cmdlet version in Powershell for backward compatibility?

若如初见. 提交于 2019-12-10 10:51:32
问题 Say you are scripting in Powershell 4.0 environment and you want to make sure the script works in Powershell 3.0. How do you ensure its backward compatible?. 回答1: Ok the question as phrased is a little more specific into what you are looking for. Sounds like you are asking for requires. The #Requires statement prevents a script from running unless the Windows PowerShell version , modules, snap-ins, and module and snap-in version prerequisites are met. If the prerequisites are not met, Windows

PowerShell script to extract .xls file from specific Outlook folder

眉间皱痕 提交于 2019-12-10 10:44:54
问题 I want to extract and save an .xls file from an email I receive daily. I have a rule set up which saves the email in an Outlook mailbox, within a specific subfolder of the Inbox. The Outlook folder structure looks like this: -> Inbox --> Data (subfolder of "Inbox") ---> ToExtract (subfolder of "Data") I need to extract the .xls file from the "ToExtract" folder. I found a script that does most of the work for me, but it requires the user to supervise the script and manually select which

Display Message Box to copy code section from it using Powershell script

杀马特。学长 韩版系。学妹 提交于 2019-12-10 10:29:09
问题 I am building install.ps1 script for Nuget pacakge and would like to open popup message at the end with some message , i have already achieved by following. [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [Windows.Forms.MessageBox]::Show("Test message ", "Test", [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) It will open popup message as per shown in below fig. Instead of this i would like put some config code here that user can

Using powershell to find files that match two seperate regular expressions

时光怂恿深爱的人放手 提交于 2019-12-10 10:16:52
问题 I want to find any file that can match two regular expressions, for example all files that have at least one of bat , hat , cat as well as the word noun . That would be any file that can match both regular expressions [bhc]at and noun . The regex parameter to select-string only seems to work on a line-by-line basis. It seems you can pass in multiple patterns delimited by commas ( select-string -pattern "[bhc]at","noun" ) but it matches either, rather than both. 回答1: You can always just use

Powershell search matching string in word document

≡放荡痞女 提交于 2019-12-10 08:46:50
问题 I have a simple requirement. I need to search a string in Word document and as result I need to get matching line / some words around in document. So far, I could successfully search a string in folder containing Word documents but it returns True / False based on whether it could find search string or not. #ERROR REPORTING ALL Set-StrictMode -Version latest $path = "c:\MORLAB" $files = Get-Childitem $path -Include *.docx,*.doc -Recurse | Where-Object { !($_.psiscontainer) } $output = "c:

How to check whether a node exists or not using powershell without getting exception?

二次信任 提交于 2019-12-10 04:35:45
问题 I am trying to check whether a particular node exists or not like follows. In my config file there is a node named client ,it may or may not available. If it is not available i have to add it. $xmldata = [xml](Get-Content $webConfig) $xpath="//configuration/system.serviceModel" $FullSearchStr= Select-XML -XML $xmldata -XPath $xpath If ( $FullSearchStr -ne $null) { #Add client node $client = $xmldata.CreateElement('Client') $client.set_InnerXML("$ClientNode") $xmldata.configuration."system