powershell

Change Generated C# Class Name

I am using ManagementClass.GetStronglyTypedClassCode to get a reference to CodeTypeDeclaration instance. I would like to change the generated class name and this method doesn't allow for this (as far as I can tell). I have tried to change the CodeTypeDeclaration.Name property, but this doesn't change constructor names etc, so the C# comp...

start-transcript causes script to fail in a background job

I am creating a powershell script as a background job using start-job which then logs it's output using start-transcript. Below is the code of both: a start-job -filepath ./b.ps1 -ArgumentList 'test.txt' wait-job * b param([parameter(Mandatory = $true)][string]$logfile) Set-PSDebug -Strict $ErrorActionPreference = 'Stop' start-tran...

Detect GPT and MBR partitions with Powershell

Is there a way to tell if a disk has a GPT or an MBR partition with powershell? ...

VitualBox + Powershell?

Hello all, I have created a virtual machine. Now I am trying to launch it using Powershell. I have searched all over the internet for any details on how to do that. This is the only code i found... ---------------------- $vBox = New-Object -ComObject VirtualBox.VirtualBox $vBox | Get-Member * $vBox.Machines $vBox.CreateMachine() --...

PowerShell, put XML into DataGrid

Hi. I would like to populate DataGrid with XML data stored in variable. Below I have working example of populating DataGrid. $grid = New-Object System.Windows.Forms.DataGrid $array = New-Object System.Collections.ArrayList foreach ($e in $(Get-Process | Select Name,Company)) { $array.Add($e) } $grid.DataSource = $array How can I do...

PowerShell: Script failing becuase AD objects have not replicated soon enough

I have a script that creates two groups, a hand full of folders, and sets permissions on those folders. In my testing environment all of these processes work without issue but in my production environment I run into a problem. Setting the permissions on the folders fail since the groups I created have not replicated through all 8 of my d...

Can I affect quoting in a Powershell tab expansion function?

Powershell tab expansion functions take 2 parameters, the line so far, and the "current word". The function should return a replacement for the current word. From experiment, it seems to me that the current word is passed to the function without any quotes, and the returned word is inserted into the line with the same quoting as the ori...

PowerShell, is it possible to translate SID to ntaccount if you are not part of the domain ?

I have this powershell code. $securityidentifier = new-object security.principal.securityidentifier $sid $user = ( $securityidentifier.translate( [security.principal.ntaccount] ) ) This code works only on a computer which is in the same domain as the user whose SID I would like to translate to ntaccount. Is it possible to translate ...

Running an exe using powershell from a directory with spaces in it

I'm trying to run MSTest.exe from C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE. What's more, I'm taking all of the assemblies in my current directory and setting them as separate /testcontainer arguments. I cannot figure out how to do this without Powershell complaining. $CurrentDirectory = [IO.Directory]::GetCurrentD...

Display directory structure with size in Powershell

Trying to have "dir" command that displays size of the sub folders and files. After googling "powershell directory size", I found thew two useful links Determining the Size of a Folder http://technet.microsoft.com/en-us/library/ff730945.aspx PowerShell Script to Get a Directory Total Size http://stackoverflow.com/questions/809014/pow...

Browse ADAM and retrive values from C#

This is my current PowerShell code: connect-QADService -service 'view.domain.com' -Credential 'MyDomain\Administrator' $AllVMs= ( get-QADObject -SearchRoot 'vdi.vmware.int/Servers' -type pae-VM -IncludedProperties ipHostNumber,pae-SIDString ) How it can be rewrited in C# (.net 3.5) ? ...

Applying a custom webtemplate to a sitecollection works on powershell ise and not on powershell console

Hi all, I'm working on a automated script for deploying sharepoint projects. I'm using a sandbox level webtemplate that must be applied when de site is created. I had a lot of troubles doing that because it seems like sharepoint caches the list of webtemplates and get-spwebtemplate doens't find the new added one. The way I made it work i...

PowerShell: How To Use Standard Output In Place of Filename

I'm writing a C# class that runs a Process (REG) to export registry keys. REG requires that you specify a filename to export to but I would rather have the output of REG directed to the standard output so I can capture it directly in my C# code (using Process.StandardOutput). Is there a way in PowerShell to specify the standard output ...

Impersonation in Powershell - Access remote file

I need to read a file on a remote server, however I dont have permissions to do so. If I use another account with elevated rights, I can. I would like to run the script from anywhere with the credentials built into the script (accepting the risks). ...

Backup Sharepoint 2010 (using Powershell - Backup-SPFarm)

I asked this on ServerFault, but didn't get any reply's, I know it's command line, but they should still be able to answer it, anyone here have any idea's? I've ran the following (task description): > Add-PsSnapin Microsoft.SharePoint.Powershell > Backup-SPFarm -Directory E:\Backups -BackupMethod Full But get this error: Backup-SPFa...

Power off WiFi on Windows 7 for battery saving

I need a way to "cut the power" of my WLan device. Currently I use a PowerShell script to disable the network interface, but I'm not sure if this also really stops the device from scanning and so on. If its possible I'd like to implement this with C++ or C# via WinAPI/WMI. Current PowerShell Script: $WLanDeviceID = 11 $WLanAdapter = g...

What is up with this PowerShell command line quoting/escaping?

I obviously don't know what I'm doing. I have finally got this PowerShell command to work. But I can't figure out why it works. My concern is the final "" chars: &"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" ` -verb:sync ` -source:contentPath="$build_directory\deploy" ` -dest:contentPath="$server_temp_dire...

Trouble scripting inputs for set-Umserver cmd let

Hi, I've writing some Exchange 2010 Unified Messaging automation scripts. I'm trying to automate the assoication of UM dial plans to UM Servers. The powershell command is : [PS] E:\Scripts>Set-UmServer -id Exchange01 -DialPlans "test1", "test2" When I try the following scripting solution: [PS] E:\Scripts>$str = "`"test1`", `"test2`...

How can I import a Site Collection to another host?

I am trying to export the content from a staging server and import it into a development machine. I've tried to do this with Backup-SPSite -Identity http://staging -Path c:/export.bin on staging and Restore-SPSite -Identity http://devmachine -Path c:/export.bin -Force on development, but after I do this, some assets (e.g. images in webp...

Sql Server Script data: SMO.Scripter not working when output to file

I get this error message when I run the Powershell script at the bottom: Exception calling "EnumScript" with "1" argument(s): "Script failed for Table 'dbo.Product'. " At :line:48 char:35 + foreach ($s in $scripter.EnumScript <<<< ($tbl)) { write-host $s } However, when I comment out the output_file line #$output_file="C:\Product.sq...