powershell

Powershell 3.0 : Alternative to “Get-Volume”

独自空忆成欢 提交于 2021-02-07 07:28:09
问题 I'm trying to get various properties for each hdd-volume on the computer. I was using the cmdlet get-volume and then walking through it via foreach , but that cmdlet does not exist in Windows Server 2008. :( Does anybody know an alternative? I just need the drive letter, objectId/guid, free space, total space, and the name of each volume. 回答1: The WMI class Win32_Volume has the information you are looking for Get-WMIObject -Class Win32_Volume | Select DriveLetter,FreeSpace,Capacity,DeviceID

How to pass a switch parameter as a variable / via splatting in PowerShell?

戏子无情 提交于 2021-02-07 07:16:48
问题 If you have multiple parameters which require a value when calling a command or a script, I know you can pass it like this: $parameters = @{ name = "John" last_name = "Doe" } But if the command or script actually just expect -T to indicate something like a flag, but the parameter itself doesn't require a value. How can I set that in a variable? $optionalT = "" if ($itNeedsTheT) $optionalT = "-T" command $optionalT If I do it like that it complains with the following message: Unknown argument

How to pass a switch parameter as a variable / via splatting in PowerShell?

…衆ロ難τιáo~ 提交于 2021-02-07 07:16:29
问题 If you have multiple parameters which require a value when calling a command or a script, I know you can pass it like this: $parameters = @{ name = "John" last_name = "Doe" } But if the command or script actually just expect -T to indicate something like a flag, but the parameter itself doesn't require a value. How can I set that in a variable? $optionalT = "" if ($itNeedsTheT) $optionalT = "-T" command $optionalT If I do it like that it complains with the following message: Unknown argument

PowerShell and ActiveDirectory module - Find Users that are not members of particular groups

坚强是说给别人听的谎言 提交于 2021-02-07 06:47:56
问题 In the last week, I have come across PowerShell and ActiveDirectory for the first time. I would like to be able to find a list of users that aren't Admins or Domain Admins. So far, I know how to get all the properties for all ActiveDirectory users with the following command/statement: Get-ADUser -Filter * -Properties * What I would like to do is to print out just the usernames of current ActiveDirectory users - that are not Admins or Domain Admins. Here is some pseudocode/Powershell code of

How to remove NULL char (0x00) from object within PowerShell

心已入冬 提交于 2021-02-07 06:47:35
问题 I have a .CSV file that I created using SQL Server's BCP command-line BULK-COPY utility to dump a bunch of database tables. Since I want to import these .CSV file's using Powershell and convert them to a nice report using the format-table cmdlet, I'm having issues with columns lining up, etc,. because some columns contain NULLs from SQL Server. I don't have the option to convert the NULL from SQL Server first; due to the way I'm exporting the table to CSV. Therefore, I would like to remove

Nuget copy and add files to solution level

帅比萌擦擦* 提交于 2021-02-07 06:47:28
问题 I want to create a NUGET package that adds several files to a certain solution folder. Specifically, the package must, on installation, do the following: Create a temp folder in the target project. Copy all the files matching an extension (say *.txt) to the temp folder. Move the files to Solution root. Create a Solution folder named "Solution Items". Add all the files just moved to that solution folder. Remove the temp folder from both solution and disk. I use the package.nuspec file to

How to remove NULL char (0x00) from object within PowerShell

馋奶兔 提交于 2021-02-07 06:47:11
问题 I have a .CSV file that I created using SQL Server's BCP command-line BULK-COPY utility to dump a bunch of database tables. Since I want to import these .CSV file's using Powershell and convert them to a nice report using the format-table cmdlet, I'm having issues with columns lining up, etc,. because some columns contain NULLs from SQL Server. I don't have the option to convert the NULL from SQL Server first; due to the way I'm exporting the table to CSV. Therefore, I would like to remove

SetCurrentConsoleFontEx isn't working for long font names

做~自己de王妃 提交于 2021-02-07 06:41:45
问题 I can't get this to work for font names that are 16 characters or longer, but the console itself obviously doesn't have this limitation. Does anyone know a programmatic way to set the font that will work with the built-in "Lucida Sans Typewriter" or the open source "Fira Code Retina"? This following code works: I have copied PInvoke code from various places, particularly the PowerShell console host, and the Microsoft Docs Note that the relevant docs for CONSOLE_FONT_INFOEX and

Pass Secret Variable from TFS Build to Powershell script

旧街凉风 提交于 2021-02-07 05:49:06
问题 I have added secret variable called Password in my build definition as shown in this image: I want to pass the Password to the PowerShell script in one of my build steps as shown in this image: My PowerShell script looks like this Param ( [Parameter(Mandatory=$true)] [string]$UserName, [Parameter(Mandatory=$true)] [string]$Password ) $appPool = New-WebAppPool -Name "test" $appPool.processModel.userName = $userName $appPool.processModel.password = $password $appPool.processModel.identityType =

Powershell 3.0 - Workflows - Limit number of parallel execution

末鹿安然 提交于 2021-02-07 05:41:51
问题 I am cloning VMs on ESX server from template. Simplified code looks like this: Workflow Create-VM { $List = 1..500 foreach -parallel ($Elem in $List) { # Create VM ... # Configure created VM .. } } Create-VM Parallel execution is really helpful. Unfortunately in this case doesn't work pretty well. Too many parallel request are generated. I need to limit number of parallel execution to smaller number (for example 4). I was trying to change local Session Configuration (SessionThrottleLimit,