|
cmdlet, writeobject, and saving to variable
My (2 input parameter) cmdlet does something and then writes a library object
via WriteObject:
protected override void ProcessRecord()
VaultServer server = foo();
...
base.WriteObject(server);
What's the correct Powershell syntax for saving this object off to a
variable so i can use it later?
(the first line here is incorrect)
Add-VaultServer $...
|
2 |
15.05.2007 00:56:04 |
|
Powershell omitted in Vista.
Why was powershell omitted in the default installation of Windows
Vista?
Why didn't the powershell team think of using UAC to elevate any
application using powershell
scripts to do certain tasks that may be virulent? And may be to have a
exclusion list (list for which UAC elevation is not required even if
it uses scripts) of application that uses ps scripts. And may be
addition to the exclu...
|
22 |
15.05.2007 02:17:47 |
|
powershell arguments : PARAM vs ARGS ?
Hi, i've got a question again :
after my multiple researchs on the internet, i still don't understand the
difference between the call of a function with
function toto($argument1, $argument2, ...)
{
...
}
or with
function toto
{
param ( [string] $arguments1, [string] $arguments2)
...
}
Could someone explain it to me ?
Than...
|
7 |
15.05.2007 01:53:40 |
|
Get_WmiObject incorrectly displays info when called twice
I have the following code put together to display first the printer states of
the printers on a print server, and then a list of the current print jobs.
Invidiually at the PowerShell prompt the following commands work and display
the data as I want them:
gwmi win32_Printjob -computername PrintServerA `
| sort-object name `
| Select-object name,document,jobstatus,...
|
3 |
14.05.2007 19:36:03 |
|
Passing Empty Strings To External Commands?
In cmd.exe, doing:
ExternalCommand.exe " "
will pass a single argument consisting a a single space to
ExternalCommand.
However doing the same in PSH appears to pass nothing (based on the
content of the arguments array passed to Main in a test .NET console
program).
Spaces in the quotes are preserved if there is a non-space character
(e.g. " . " is passed through including t...
|
4 |
14.05.2007 18:59:33 |
|
Powershell and cmdlet config files
I just wrote my first cmdlet. It uses a config file. The first time, i:
installutil mycmdlet.dll
Add-PSSnapIn mycmdlet
I set a breakpoint in the cmdlet, and verified that it read the config file
fine.
However, i made a change to the config file. I Removed the snapin, and
installutil -u the dll. Rebuild the dll and config file, reinstalled it,
but... it's not reading ...
|
4 |
14.05.2007 14:23:55 |
|
Newbie: filter rows with variable
Hi,
I want to call a .ps1 script with a parameter which is used as a
parameter to limit the rows read from a file.
I have tried the following:
ps> list.ps1 <searchcriteria>
list.ps1:
gc c:\temp\test.txt | where {$_ -like "*$args*"} | sort
but I cant get it to work. It does not fail but no rows are returned.
What is wrong here?
Also, when the parameter includes @ (e.g....
|
4 |
14.05.2007 12:50:22 |
|
win32_product not valid
I am in the process of writing a query for win32_product but the component is
not installed on some of our boxes. I don't have the luxury of adding this
component, is there a another way to gather installed apps on a server via
powershell?
Thanks in advance,
...
|
4 |
12.05.2007 22:10:55 |
|
Stderror redirect bug?
I think I might have found a bug. The following command (3rd line) properly
redirects the error stream to the file:
copy-item *.ps1 c:\temp
gci c:\temp\*.ps1 | %{$_.IsReadOnly = $true}
copy-item *.ps1 c:\temp 2>&1 > foo.txt
However if I now add -force, the error stream is no longer redirected to the
file:
copy-item *.ps1 c:\temp -force 2>&1 > foo.txt
That's got to be...
|
5 |
12.05.2007 22:08:47 |
|
Wait for invoke-expression completion
After an invoke-expression statement, how can you make the script wait for it to complete?
My workaround for this is to the start-sleep cmdlet, with a safe time interval to ensure completion.
Is there a simple, more straightforward way?
- Doug
...
|
4 |
12.05.2007 20:48:59 |
|
HttpWebRequest won't work in PowerShell without a Proxy
I am trying to get a web page using System.Net.HttpWebRequest. When there is
no web proxy in use, it won't work. However, when there is a proxy, it works
without problem. I can reproduce the problem from the command line as
follows:
PS C:\> $httpRequest =
[System.Net.WebRequest]::Create("http://www.microsoft.com")
PS C:\> $x=$httpRequest.GetResponse()
Exception calling "GetRe...
|
3 |
12.05.2007 17:53:45 |
|
alternatives to Console ?
Hi, i'm looking for an application that could contain multiple dos
(powershell) terminals into one single window, like the freeware Console :
something disturbs me on this one but i don't know what.
Do you know another freeware like this one ?
bye
Nico
...
|
7 |
12.05.2007 15:08:38 |
|
Ctrl-C on powershell
Hi, is there any way to break the scripts by typing a "key group" like the
"Ctrl+C" in a dos console, without closing the window ?
bye
Nico
...
|
3 |
12.05.2007 15:06:35 |
|
can my cmdlet/snapin have a config file?
I just built a cmdlet/snapin for Powershell. it has a myCmdlet.dll.config
where it's installed. However, i'm not getting anything inside the cmdlet
when i do a:
COnfigurationManager.AppSettings["foobar"]
How do cmdlet configuration files work?...
|
3 |
12.05.2007 11:05:38 |
|
select-string to act like grep -v
Does anyone know how to use select-string to print out everything except some
string. ie. grep -v dontwantstring file.txt.
Thanks in advance,
...
|
6 |
12.05.2007 05:59:57 |
|
-LiteralPath is a less than optimal solution
The team probably already knows this but the -LiteralPath hack is *not*
ideal. First when you write a script or function library you have to
pick -path or -literalPath. Unless you are a psychic, you should probably
pick literalPath if you think someone will ever call your function with a
path containing special chars ([ ],*, etc). However that precludes the use
of any wildcard charact...
|
10 |
12.05.2007 05:57:41 |
|
Tab expansion on path's with square braces is broken
This is a multi-part message in MIME format.
------=_NextPart_000_05F9_01C7941E.30A38120
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
FYI,
980# dir '(2+2)+$f;{@()}`[a-z`].txt'
Get-ChildItem : Cannot find path 'C:\MemStick\Brown Bags\Windows =
PowerShell\Samples\(2+2)+$f;{@()}`[a-z`].txt' because
it does not exist.
At line:1 char:4
+...
|
1 |
12.05.2007 04:46:18 |
|
Start learning PS
Hi
as a starter, I want to create some scripts to manipulate a file or
two.
The idea is to script up a simple todo.txt file to add add entries
(activities), change entries, search entries etc. (Like http://www.todotxt.com)
I want to manipulate the file by adding commands at the commant
prompt, e.g. "add <some text here>" or "list <searchcriteria>".
As a "proof of concept" I w...
|
5 |
12.05.2007 02:39:49 |
|
How can you remotely instantiate a WMI class?
Hello again,
I have a script setup to create a printer locally using WMI, using the
following code:
$PRINTERCLASS = [WMICLASS]"WIN32_PRINTER"
$MYPRINTER = $PRINTERCLASS.CREATEINSTANCE()
I know that I can remotely hit wmi via gwmi -comp remotecomputer
win32_printer, but I'm not sure how one would go about instantiating an
object remotely, since there doesn't seem to be a built-in wa...
|
4 |
11.05.2007 21:57:39 |
|
Add Date and time to filename
How do I add the date and time onto a filename I am generating in format
somefilename20070511-0911 ?
Thanks...
|
5 |
11.05.2007 21:02:14 |
|
Win32_Share
OK.... this is more of a WMI question than a Powershell question...
I need to verify that a share is available to "Everyone". I was using
gwmi Win32_Share to do the check, but according to MSDN, the results
of the GetAccessMask method "Returns the access rights to the share
held by the user or group on whose behalf the instance is
returned.".
How do I get the Win32_Share instance for "E...
|
3 |
11.05.2007 20:49:30 |
|
Powershell Security : encrypting a script
Hi
In VB Script there were editors such as Systemscripter that were able to
encrypt the contents of the script file. The encrypted script file could be
given to someone else, and they could run the script as a normal vbs file,
but if they opened the script file in notepad in would be a series of numbers
and character ie. it was encrypted.
Is it possible to do the same with a Powers...
|
15 |
11.05.2007 19:17:05 |
|
functions libraries
Hi, could you tell me how to make a library of my own powershell functions
in a separate file ?
i mean : is there a way for importing some instruction in Powershell from
another file, like a "using functions.ps1"?
Thx
Nico
...
|
7 |
11.05.2007 18:43:49 |
|
Out-File -Force doesn't seem to work as advertised
This is a multi-part message in MIME format.
------=_NextPart_000_003A_01C793B4.BC3206E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I'm having a bit of trouble with Out-File, from Get-Help Out-File =
-detailed:
-force <SwitchParameter>
Overrides restrictions that prevent the command from succeeding, =
just so the changes do ...
|
2 |
11.05.2007 18:18:40 |
|
You cannot call a method on a null-valued expression
Does anybody know why this script is failing?
I've tried to extend a script describing how to use PowerShell with the
RegistryKey CLR class (inspired by
http://mybsinfo.blogspot.com/2007/01/powershell-remote-registry-and-you-part.html,
along with Jeffrey Snover's enhancements). I was able to reproduce the
effects of that script, which enumerates subkey names and value names on a
r...
|
2 |
11.05.2007 14:57:50 |