I have a complex Powershell script that gets run as part of a SQL 2005 Server Agent Job. The script works fine, but it uses the "Start-Transcript $strLogfile -Append" command to log all of it's actions to a transcript file. The problem is that the transcript is always empty. It adds the header and footer to indicate that the transcript i...
Hi,
I have a signed PowerShell script which I want to deploy to a target machine via a WiX installer. Is it possible to give the script the execution rights?
Regards,
forki
EDIT -
It seems I have to call Powershell with --Command Set-ExecutionPolicy RemoteSigned, but I can't get it working. I see the Powershell command window openi...
How to get current running application in PoSh?
...
Working on a Powershell script I had several places where I wanted A unless it was null, else B. Essentially the ?? operator in C#. I ended up writing the function shown below, but I can't help but think there is a built-in way to do this.
Is there a better, built-in, way?
function Get-ValueOrDefault()
{
foreach ($value in $args)...
I have a flaky NIC that drops out from time to time, especially after resuming from hibernation. A drop-out corresponds to Vista's network status showing in the notification area as "Local Only". Is there a way of retrieving these status values (e.g. "Limited Connectivity", "Local Only", "Local and Internet") programmatically?
I am writ...
I'm calling Powershell like so:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -noninteractive -nologo -file "C:\Users\dummy\Documents\dev\powershell\samples\test.ps1"
I'm calling it from a python script, but the same problem can be observed if called via a shortcut. I thought the -NonInteractive flag would cause...
I am a powershell novice.
After days of searching....
I have put together a small powershell script (as below) to check page file, /PAE switch, /3GB switch, SQL server max RAM, min RAM.
I am running this on 1 server.
If I want to run it on many servers (from a .txt) file, How can I change it ?
How can I change it to search boot.ini fi...
In a PowerShell script I am trying to get the number of page faults per second with this command:
(Get-WmiObject Win32_PerfFormattedData_PerfOS_memory).PageFaultsPersec
Unfortunately, it reads always the same value because I don't Refresh() the performance counter.
How can I send a Refresh() method to Pervormance Data via PowerShell?...
Given this function:
> function Get-ArrayOfArrays() {
(1,2),(3,4) | % { $_ }
}
I'd expect the return type to be an array of arrays. However, it appears that the inner arrays are being expanded into the pipe:
> Get-ArrayOfArrays | % { $_.GetType().Name }
Int32
Int32
Int32
Int32
In fact, running the pipe inline will produce thes...
Consider this code:
PS> $timer = New-Object Timers.Timer
PS> $timer.Interval = 1000
PS> $i = 1;
PS> Register-ObjectEvent $timer Elapsed -Action { write-host 'i: ' $i }.GetNewClosure()
PS> $timer.Enabled = 1
i: 1
i: 1
i: 1
...
# wait a couple of seconds and change $i
PS> $i = 2
i: 2
i: 2
i: 2
I assumed that when I create new clo...
My code below works perfectly on a 32-bit Windows machine, however it refuses to work on a 64-bit machine due to the 32-bit WMI class win32reg_addremoveprograms used in the code. Is there a 64-bit equivalent of this class?
$ServerFile = "D:\SharePoint\Powershell\AddRemovePrograms\Machines.txt"
$ServerList = Get-Content $ServerFile
$Exc...
In Bash I can easily do something like
command1 && command2 || command3
which means to run command1 and if command1 succeeds to run command2 and if command1 fails to run command3.
What's the equivalent in PowerShell?
...
I've done some work hosting PowerShell and have done a lot of reading but I am seeing strange behavior and it makes me wonder if I do not understand the host like I thought I did.
I am creating a Runspace with RunspaceFactory:
var runSpace = RunspaceFactory.CreateRunspace()
I'm utilizing the same runspace throughout the execution o...
Hi,
I'm new to PowerShell and am trying to query against my SQL server. I get the idea of creating a new-psdrive and then navigating to databases etc and have a line of code as
$dbs = (get-childitem
sqlserver:\sql\SERVER\INSTANCE\databases)
when I pipe the $dbs to a foreach, how would I get results of a collection of the databa...
Environment Overview:
3 WFEs
1 Admin Server
1 Index + 1 Query server
Requirement: We want to generate the below reports
We have to compare the "12hive" folder on a server with other servers.
We have to compare the GAC of a server with other servers.
thoughts?
...
In PowerShell how to capture error, warning, write-host output into a single file?
When I execute the external command/ write-warning/ write-error/ write-host I need all the information to be captured in a file.
when I redirect the write-error to a log file it will not show the same content as it's been displayed on the console. It wil...
I'd like to use a windows powershell to run a batch file every x number of seconds. So it's the same batch file being run over and over again.
I've done some looking but can't find what i'm looking for. It's for something that i want to run on a windows xp machine. Windows Schedular i've used lot of times before for somethign similar...
Hi,
I want to do something like this...
try
{
# Something in this function throws an exception
Backup-Server ...
}catch
{
# Capture stack trace of where the error was thrown from
Log-Error $error
}
Ideally I'd like to capture arguments to the function and line numbers etc. (like you see in get-pscallstack)
E...
I want to compare two CSV files to see if they are different. I was thinking I could do that with Compare-Object, but that doesn't seem to work.
$csvA = ConvertFrom-CSV "A,B,C`n1,1,1`n1,1,1"
$csvB = ConvertFrom-CSV "A,B,C`n1,1,1`n1,1,2"
Compare-Object $csvA $csvB
There is no output on the last line. Why is that?
...
For a check i need yesterday's date at 10:00pm in a variable.
I get yesterdays Date and current Time with
$a = (get-date).AddDays(-1)
But how do i manipulate the time to 22.00 and leave the variable still as Date-Object?
...