powershell-2.0

Output all Invoke-Expression in PowerShell v2

回眸只為那壹抹淺笑 提交于 2019-12-12 03:28:19
问题 Trying to run an command-line executable from within a PowerShell script, unfortunately the current limitation is the host running only version 2. The command runs fine, however it appears to only be partial output that is added to the variable, and just by chance the most important information is being missed. Is there anyway to capture everything into the output? $output = Invoke-Expression ($itemCommand) Write-Output $output Testing on v3 and v4 works just fine, in fact was able to get

Count number of spaces, and split at the last one

…衆ロ難τιáo~ 提交于 2019-12-12 02:04:17
问题 I have a string simliar to: c:/folder name/somewhere/application.exe instanceName (n.b. the space in "folder name" is intentional) I need a way to split this into: [0]c:/folder name/somewhere/application.exe [1]instanceName I was going to use split-path , but apparently there is a bug in powershell v2 that stops me doing this: Split-Path : Cannot find drive. A drive with the name ' So, I figured if I count how many spaces there are, and then simply use -split() to split it at the last space.

Automating the creation of Homedrive of a newly created AD user

江枫思渺然 提交于 2019-12-12 00:29:44
问题 I have made a script to create a homefolder(by the name of SAMAccountname) for a newly created AD user. $ADServer = 'xyz1' Import-Module ActiveDirectory $searchbase = "OU=xyz2,OU=xyz3,DC=xyz4,dc=xyz5" $ADUsers = Get-ADUser -Filter {name -eq "xyz6"} -Server $ADServer -SearchBase $searchbase -Properties * New-Item -ItemType Directory -Path "xyz7\$($ADUsers.sAMAccountname)" Everything is automated except the fact that I have to feed in the name of the user (AD account name) to make it search for

How to store data from foreach function in HTML file in powershell and get Physicall ram

不羁岁月 提交于 2019-12-11 23:57:34
问题 I have written a for each file which stores the BIOS information of the systems in a network and the result is being displayed on my console but I want them to be in a HTML file in an order. Code: $arrComputers = get-Content -Path "C:\Computers.txt" foreach ($strComputer in $arrComputers) { $colItems = get-wmiobject -class "Win32_BIOS" -namespace "root\CIMV2" ` -computername $strComputer foreach ($objItem in $colItems) { write-host "Computer Name: " $strComputer write-host "BIOS Version: "

powershell v2 : WebClient/UploadString never connect

青春壹個敷衍的年華 提交于 2019-12-11 21:22:29
问题 with powershell v2 and pushbullet, I try to send push notification when a file in modified $folder = 'c:\path\to\file' $filter = '*.*' $user = "pushbullet_token" $url = "https://api.pushbullet.com/v2/pushes" $fsw = New-Object IO.FileSystemWatcher $folder, $filter $fsw.IncludeSubdirectories = $true $fsw.NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite' $onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action { $name = $Event.SourceEventArgs.Name $path = $Event

BIZTalk210 powerscript to stop and start SEND PORT

▼魔方 西西 提交于 2019-12-11 18:27:03
问题 BIZTalk2010 powerscript to stop and start SEND PORT I got the receive location working ok. BizTalk2010 restart Receive location every hour Now I need to do the same with the send ports. But it does not work. # a. Set Server name in ConnectionString -- # b. Set ($hostname) host name value that is using in SFTP send location # c. Set ($sndLocation) send location name $Catalog.ConnectionString ="xxx" $hostname = "bbb" $sndLocation = "SndPrt_XXXXXXX001" #send location # Function to retrieve the

Putting formula in cell with Powershell

一笑奈何 提交于 2019-12-11 17:45:04
问题 I have an issue putting a formula in an excel cell. The formula contains a variable. $batchname = Batch15c $ws.Cells.Item(2,5).value() = "=VLOOKUP(RC[-1],[$batchname]Sheet1!$A$1:$D$300,2,FALSE) I get the following error:-Exception setting "Value": "Exception from HRESULT: 0x800A03EC" anybody got any ideas? 回答1: I believe should be setting the Formula property instead of Value . Try: $ws.Cells.Item(2,5).Formula = "=VLOOKUP(RC[-1],[$batchname]Sheet1!$A$1:$D$300,2,FALSE)" 来源: https:/

calling powershell functions through c#

房东的猫 提交于 2019-12-11 17:35:06
问题 I'm trying to call PowerShell function through c# code. **#This is sample PowerShell function** function Add-num { param($int1,$int2) Write-Host ($int1 + $int2) } **#This is my c# code** class Program { static void Main(string[] args) { String file = @"E:\powershell\Untitled3.ps1"; Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); using (PowerShell PowerShellInstance = PowerShell.Create()) { PowerShellInstance.AddScript(file); PowerShellInstance.AddCommand("Add-num")

How to output multiple file extensions stored in a .txt file on Powershell

淺唱寂寞╮ 提交于 2019-12-11 14:42:26
问题 my purpose is to output the files with the extensions that match the ones I store on a .txt file but I don't know how to make it work. The way I am trying to do now does not generate any output or output the files of the extensions that are not on the text file (Extension.txt) I indicate. How am I supposed to fix this? The content in my .txt file is: *.xlsx,*.xlsm,*.xlsb,*.xltx,*.xltm,*.xls,*.xml My current code is as followed: $fileHeaders = @('country','cDrive','dDrive') $extensions = ${C

Is new-pssession the same as psexec?

馋奶兔 提交于 2019-12-11 14:35:29
问题 Is pssession the same as psexec ? If I use new-pssession to create a session to a remote PC, is it the same as using psexec ? If we can use invoke-command -computername to create a temporary session, what is the benefit using pssseion to create a persistent connection? Under what circumstances should I use new-pssession ? 回答1: New-PSSession is used when you have multiple commands, or even a script, to be run against a remote machine. Invoke-Command and psexec both allow you to run a single