Steps to reproduce:
Create a TestAlias module in \WindowsPowerShell\Modules\TestAlias\TestAlias.psm1 with the following function and alias:
function foo
{ write-output 'foo' }
New-Alias -name bar -value foo
From Powershell a session
import-module TestAlias
bar
The term 'bar' is not recognized as the name of a cmdlet, function...
Just getting started with PowerShell. I was running DOS .bat files in my post build events in VS and wanted to graduate up to PowerShell. Bat files were easy...CALL something.bat. I tried to do that with a PowerShell ps1 file and my trial-and-erroring got me to the following (first thing that worked...tried all the simple things first...
Hi,
I have a directory of videos (.AVI files) that I want to determine the duration of, and to create a file listing the titles and durations of all the videos, sorted in descending order of the video duration.
Can anyone offer a PowerShell script to do this?
Thanks, MagicAndi
...
Hi,
I am trying to get the "date of birth" column in my excel sheet compared with system date & get the matches. The next step would be to get the associated datas(login names) in the same row, of the matched dates & display the same or dump the data to any file somewhere.
This is what I have now:
$link
= "http://sp-fin/sites/arindam-s...
PowerShell's help (powershell -?) states:
-Version
Starts the specified version of Windows PowerShell.
However, when starting PowerShell 2 with powershell -Version 1 all things I tried that are only present in v2 and not v1 still work, such as the -split operator or the Get-Random cmdlet.
So what exactly changes when running Power...
Hi,
I have been trying to create a post login script that will change the default gateway to a specific IP and then renews its IP but haven't had any luck. I know the normal cmd line is ipconfig \renew for renewing it IP. Any help would be appreciated.
Thanks
...
Hi,
I on occasion I get asked to produce a list of users who have Full Access rights to a particular Exchange 2007 Mailbox. At the moment I am doing this manually, and I'd ideally like to do it with Powershell.
Is there anyway to produce a list of Full Access Permissions (and Send On Behalf rights would also be useful).
Thanks,
Jonny...
Sometimes we need to perform small administrative tasks in SharePoint. A simple PowerShell script is a really good tool for that. For instance, such script can enumerate event handlers of a list:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = new-object Microsoft.SharePoint.SPSite($args[0])
$site.Ro...
I'm writing a Windows batch file and want to copy something to the desktop. I think I can use this:
%UserProfile%\Desktop\
However, I'm thinking, that's probably only going to work on an English OS. Is there a way I can do this in a batch file that will work on any internationalized version?
UPDATE
I tried the following batch f...
Can anyone tell me how to create a scheduled task using powershell that runs as the local system or local service?
Everything works great except the call to ITaskFolder.RegisterTaskDefinition().
If I pass in $null, or "", than the call bombs saying invalid username or password.
Any thoughts"
$Rootfolder.RegisterTaskDefinition("Test", ...
Why are the variable assignments that I make inside the Trap block not visible outside it?
$integer = 0;
$string = [String]::Empty;
$stringBuilder = new-object 'System.Text.StringBuilder';
trap
{
$integer = 1;
$string = '1';
$stringBuilder.Append('1');
write-host "Integer Variable Inside: " $integer;
write-host "St...
API:
namespace ClassLibrary1
{
public class Class1
{
public static string Test(string input)
{
if (input == null)
return "It's null";
if (input == string.Empty)
return "It's empty";
else
return "Non-empty string of length " + inpu...
I have a scheduled task which executes a powershell script every hour. The powershell script must make a call to a one-way WCF service operation. Essentially it just needs to kick off an operation. My question is how do i go about doing that? I thought that just executing the url would in fact kick off the request but apparently that...
Somehow I can't read an XML file with very simple structure in my PowerShell script. The XML file is generated by "Microsoft Log Parser Toolkit" and I want to load its contents into a database.
The script is very simple:
$datalist=[xml] (gc ".\users.xml");
foreach ($ROW in $datalist.ROOT.ROW) {
Write-host $ROW.CompName;
}
The...
I'm trying to execute a wcf service operation from PowerShell using the following script.
$uri = "http://myserver.com/myservice.svc?wsdl"
$proxy = New-WebServiceProxy -Uri $uri
$proxy.CleanupExpiredTransactions()
However, I am getting the following exception.
Exception calling "CleanupExpiredTransactions" with "0" argument(s):
"Object...
When I run my script directly from the Powershell console it works. When I run my script in PowerGUI and try instantiate an object, I get an error:
Exception calling ".ctor" with "3" argument(s): "Could not load file or assembly 'MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=77f676cc8f85d94e' or one of its dependencies. The s...
I have a list of filenames in a text file like this:
f1.txt
f2
f3.jpg
How do I delete everything else from a folder except these files in Powershell?
Pseudo-code:
Read the text file line-by-line
Create a list of filenames
Recurse folder and its subfolders
If filename is not in list, delete it.
Thanks in advance.
~HP
...
As part of a simple backup process, I would like to save files with the name indicating the date and time of the backup. Right now I am using yyyyMMddTHHmmss, i.e. "20100601T115720". I would like to be able to parse those dates back to allow clean up of files older than a certain date. (The backup date time is not necessary the same as t...
My script's input parameter is a date or a number. Here's a script that works fine, so you can see what I am trying to do:
param($date = (Get-Date))
if ($date -match "^\d+$")
{
$date = (Get-Date).AddDays($date)
}
elseif ($date -as [DateTime])
{
$date = [DateTime]::Parse($date)
}
else
{
'You entered an invalid date'...
I'm trying to run a Powershell script without leaving Eclipse IDE so I setup External tool config as follows:
under "main" tab:
Location: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe
Working Directory: C:\WINDOWS\system32\windowspowershell\v1.0\
Arguments: "& C:\PowershellScripts\script.ps1"
I save it and click run but ...