Can someone help me explain what is happening here? Sorry if this is a basic question,
I simplified it from a pipeline expression I'm trying to write:
$foo = pwd
$cmd = "dir"
& $cmd $foo #Works
dir $foo #Works
& "dir $foo" #Error
*The term 'dir C:\' is not recognized as a cmdlet, function, operable program, or script file. Verify ...
Background
Python has "textwrap" and "dedent" functions. They do pretty much what you expect to any string you supply.
textwrap.wrap(text[, width[, ...]])
Wraps the single paragraph in text (a string) so every line is at most width characters long. Returns a list of output lines, without final newlines.
textwrap.dedent(tex...
On Linux, I can do:
$ FOO=BAR ./myscript
to call "myscript" with the environment variable FOO being set.
Is something similar possible in Powershell, i.e. without having to first set the variable, call the command, and then unset the variable again?
To be more clear about my use case - I don't want to use this as part of a script. R...
The script runs fine when stdout/stderr are not redirected.
When I add both stderr and stdout redirection, I getg the following error:
How can I avoid it?
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 19.4M 0 0 ...
I'm trying to create an external MAML help file for a script Module. As a test I created a simple module called "ModTest" with 2 functions saved in a .psm1 file:
function Test-SqlScript2
{
}
function Out-SqlScript2
{
}
I saved the module in my user Modules directory ~\Documents\Modules\ModTest
Next I created a subdirectory for a MAML...
I am using Oracle.DataAccess.Client inside Powershell. What I need to do is INSERT a new row of data, then retrieve the auto-generated ID field of the newly-created row for another INSERT command, immediately following. What is the best way to do this? I am pretty new to SQL and Oracle. Here is some of my code:
$conn = "My Connection St...
Background:
Powershell history is a lot more useful to me now that I have a way to save history across sessions.
// run this every time right before you exit powershell
get-history -Count $MaximumHistoryCount | export-clixml $IniFileCmdHistory;
Now, I'm trying to prevent bash powershell from saving duplicate commands to my history.
...
Is there any API in Microsoft DNS Server 2008 to add new forward DNS using VBScript or PowerShell or P/Invoke or WMI?
It's easy to generate plain text file and put it into \system32\dns.
How to replace a number manual commands in MMC with just a script execution?
...
When using powershell to retrieve info about events Message column gets trimmed and is too short:
Index Time Type Source EventID Message
----- ---- ---- ------ ------- -------
2 Sep 18 12:50 Info yaddayadda 0 Class: Controllers.BasketController...
1 Sep 18 12:...
I am writing some Internet Explorer automation scripts using PowerShell. Here is how I start the IE com object:
$ie = New-Object -com "InternetExplorer.Application"
$ie.Navigate("about:blank")
$ie.visible = $true
$doc = $ie.Document
So, what I would like to do is to execute some javascript on the $doc object. For example, I have an i...
PowerShell can call commandline batch files. PowerShell script output can be recorded with the "tee" command. But the tee command does not record the output of batch files inside a PowerShell script for me in PowerShell 1.
Try this cut-down example:
Make a batch file, called test.bat, with contents
@echo hello from bat
Run it from P...
Background:
Suppose I have a powershell function that understands and interprets small_commands such as:
todolist.additem/title=shopping/body=get milk
Suppose further that I invoke the function like this:
myfunc [small_command goes here]
Question:
Is there a way that I can type in the small_command and still have powershell invoke...
I have a PowerShell script that needs to run normally, and also when invoked via RunspaceInvoke, e.g.
using (RunspaceInvoke invoker = new RunspaceInvoke())
{
invoker.Invoke(powerShellScript);
}
Part of this script doesn't need to run when being called with RunspaceInvoke, and moreover, it fails when being called with RunspaceInvok...
Is it possible to know the return value prepared by powershell before returning from function?
Pseudo code:
function Foo()
{
1
2
Write-Host $CURRENT_RESULT # I would like it to print [1, 2]
3
4
Write-Host $CURRENT_RESULT # I would like it to print [1, 2, 3, 4]
}
...
I'm creating a PowerShell script to automate a process at work. This process requires an email to be filled in and sent to someone else. The email will always roughly follow the same sort of template however it will probably never be the same every time so I want to create an email draft in Outlook and open the email window so the extr...
I'm particularly interested in Windows PowerShell, but here's a somewhat more general complaint:
When asking for help on learning something new, be it a small subject on PHP or understanding a class in Java, what usually happens is that people direct me towards the documentation pages.
What I'm looking for is somewhat of a course. A d...
I have a problem where Windows discards custom ICC display calibrations whenever an external monitor is hot-plugged into my system. I believe this applies to both Windows 7 and Windows Vista. I want to automate pushing the "Reload current calibrations" button on the advanced tab of the Color Management control panel applet. Ideally, I'd ...
I found this function in my old powershell folder:
Function listAllPaths([string]$fromFolder,[string]$filter) {
Get-ChildItem -Path $fromFolder -Recurse $filter | Select-Object -Property FullName
}
And wanted to test it out. I put it in my profile, started Powershell and typed the following:
PS C:\> listAllPaths("C:\Downloads\Nemi"...
Background: Here the goal is to do some basic commands in powershell using select-string. For some reason, there are certain things that are not working as expected.
Assume the following:
$vfilter = 'c:/foo/bar/files/*.htm';
Select-String -path $vfilter -pattern ".*DOCTY.*" |
sort LineNumber |
where-object { $_...
I'm writing a fairly simply script and I'm trying to upload a file to an ftp server. I'm using the following command
ftp -n -s:upload.txt 292.78.51.12 (I've faked the IP)
It works perfectly in command prompt but it seems to have a problem with it in powershell.
I've tried giving the absolute path to upload.txt, put .\ before it and no...