powershell-4.0

PowerShell PipelineVariable parameter contains only first value in a collection of PSCustomObject

和自甴很熟 提交于 2019-12-13 00:27:19
问题 Question I get count for lines of code for only one file in the array of type PSCustomObject . Rest all entries in the array error out with following message - Get-Content : Cannot bind argument to parameter 'Path' because it is null. At line:42 char:100 ... -Content -Path $files.UncommentedFileName) | Measure-Object -Line | Select-Objec ... How do I overcome this error and display the lines of code for all the files in the array? Constraints I intend to re-use the function Remove-VBComments

In Powershell how can I convert the date 'June 6th 2017, 08:09:05.000' to [DateTime]?

橙三吉。 提交于 2019-12-13 00:13:57
问题 When tried converting I received the following error message apparently because of the th symbols. Cannot convert value "June 6th 2017, 08:09:05.000" to type "System.DateTime". Error: "The string was not recognized as a valid DateTime. There is an unknown word starting at index 6. 回答1: The simplest method is probably to remove those characters. I'm pretty sure you could do this with Parse or ParseExact but I would just op for remove the "th" instead for the ease. $date = "June 6th 2017, 08:09

Real Time Data With Powershell GUI

喜欢而已 提交于 2019-12-12 17:38:46
问题 I'm struggling here. Using Powershell and GUI, how to automatically refresh data on a form? Example with the script below, how to automatically update the label with the number of process executed by my computer? Add-Type -AssemblyName System.Windows.Forms $Form = New-Object system.Windows.Forms.Form $Form.Text = "Sample Form" $Label = New-Object System.Windows.Forms.Label $Label.Text = "Number of process executed on my computer" $Label.AutoSize = $True $Form.Controls.Add($Label) $Form

Additional Outputs Based On Group Memberships

℡╲_俬逩灬. 提交于 2019-12-12 15:32:02
问题 I hope you all are having a great day. I apologize in advance if this is a terrible attempt at a question, I'm not very good at this. Introduction So First of all, I'd like to introduce what I am actually creating. I work for a MSP, and I've been tasked with creating a User Management Powershell Script to be used for one of our Customers so that we can easily manage users and automate a lot of our user creation processes. I have run into an issue, which is why I am asking for help The Issue

powershell putting linebreaks inappropriate places in output

守給你的承諾、 提交于 2019-12-12 11:46:20
问题 I have a PowerShell script, but some of the output gets cut at an arbitrary point before continuing on the next line. This is incredibly annoying. For example, I can use Write-Host and the line will continue on as long as I want it (note, that is running in Team City and Team City adds some prefix information - however the same effect can be observed piping the output to a file): [10:04:45] [Step 5/7] - Found Windows Service at G:\TeamCityData\TeamCityBuildAgent-1\work\282b8abc9094651e

Running Scheduled Tasks with Powershell

Deadly 提交于 2019-12-12 06:19:32
问题 I started coding in Powershell today and noticed that when I ran scheduled tasks via powershell, it wouldn't register as running in the Task Scheduler( Run "Taskschd.msc" ). The code I'm using is here: Get-ScheduledTask -TaskPath "\TaskPathHere\" | Start-ScheduledTask When I run a task manually( right-mouse click>Run ), the status changes from Ready to Running . This isn't the case when ran from Powershell. Question: Is there some additional parameter I need to pass to change the Status, or

Powershell - Import local CSV

时间秒杀一切 提交于 2019-12-12 05:32:16
问题 I have a powershell script that imports a CSV file using this command: $empCsv = Import-Csv "addEmp.csv" I have the csv sitting in the same directory as the script but I'm getting a FileNotFoundException . If I use the command with a path to the CSV like this: $empCsv = Import-Csv .\Desktop\createUser\addEmp.csv It works fine. I want to be able to give this script to someone to use and let them run the script from any location and be able to import the .csv that's sitting in the same

Copy File On Creation (once complete)

 ̄綄美尐妖づ 提交于 2019-12-12 04:42:18
问题 I have the below code to detect the creation of a new file and grab a copy of it. $folder = '\\server\share\monitor_me\' $filter = '*.*' $copyToFolder = 'C:\temp\capture\' $fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $true;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'} #protection from previous runs unregister-event -SourceIdentifier FileCreated -ErrorAction SilentlyContinue Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated

Running Powershell Start-Process With -Credential makes script hang (Windows Server 2012)

女生的网名这么多〃 提交于 2019-12-12 04:37:04
问题 I have come across a rare occurrence as this cannot be replicated on my own machine however on one of our Windows Server 2012 instances it occurs. The script I invoke looks like this $arg="D:\Scripts\test.ps1" $securePassword = ConvertTo-SecureString $password -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential $username, $securePassword Start-Process -FilePath powershell.exe -Credential $Credential -ArgumentList $arg This piece of code just hangs on the

Powershell to group items separated by commas as they relate to another value on other column

孤人 提交于 2019-12-12 04:20:00
问题 need some help with powershell and manipulating csv files, as I'm a newbie trying to learn. I've got a .csv file with several columns, for now lets refer to them as A, B, C, D In column 'A' I have URLs, Column 'B' I have Groups, C and D are of o importance for this example. so as far as the values in the cells below each column, obviously the Values of URL are tied to the Value of those under Group Column 'B'. Sample csv: URL,Groups,x,y test1.org,TestGroup,xxx,yyy test2.org,TestGroup,xxx,yyy