powershell-3.0

Powershell - DHCP Scopes in Powershell

不羁岁月 提交于 2019-12-24 08:56:36
问题 Working on a script to fully automate the deployment of a new 2012 box as a DC - with Windows updates configured, AD installed, Forest Created, DNS zones configured, DHCP scopes activated etc. I am working on the DHCP part at the moment and have the following: Add-WindowsFeature -IncludeManagementTools dhcp netsh dhcp add securitygroups Restart-service dhcpserver Add-DhcpServerInDC $Env:COMPUTERNAME $ip Add-DhcpServerv4Scope -Name "Client LAN" -StartRange $ipRangeStart -EndRange $ipRangeEnd -

no receive-job results for gci when -path is a variable

谁说我不能喝 提交于 2019-12-24 07:40:33
问题 This returns nothing: $x = "C:\temp" Start-Job -ScriptBlock {get-childItem -path $x} | Wait-Job | Receive-job But providing the path parameter without a variable, like so... Start-Job -ScriptBlock {get-childItem -path C:\temp} | Wait-Job | Receive-job ...returns the contents of that temp folder, durrr.txt in this case. This is on Windows Server 2008R2 SP1 with Powershell $host.version output as follows: Major Minor Build Revision ----- ----- ----- -------- 3 0 -1 -1 Suspecting Powershell's v3

PowerShell Script digitally signed error

无人久伴 提交于 2019-12-24 06:29:13
问题 I'm getting an error when I run a PowerShell script: File test_new.ps1 cannot be loaded. The file test_new.ps1 is not digitally signed. I created a CA and a certificate and signed this file using the procedure described here. Here is when I do a dir on the MY directory: EF76B3D7D8D2406E1F2EE60CC40644B122267F18 CN=PowerShell User I can see the signature block appended at the end of the test_new.ps1 file. Here is the execution policy and scope: Scope ExecutionPolicy ----- ---------------

Empty value powershell array

╄→尐↘猪︶ㄣ 提交于 2019-12-24 02:39:09
问题 I have a strange issue, this is my CSV: Serveur;Carte;Cordon;IP;Mac;Vmnic ;Vmnic mac;Connect;Port Dexter;eth1;405;172.16.5.117;00:24:e8:36:36:df;Vmnic0;00:50:56:56:36:df;sw-front-1;A1 Dexter;eth2;14;192.168.140.17;00:24:e8:36:36:e1;Vmnic1;00:50:56:56:36:e1; sw_eq_ds_1;3 ;;;;;;;; Gordon;eth1;404;172.16.5.124;b8:ac:6f:8d:ac:b4;Vmnic0;00:50:56:5d:ac:b4;; Gordon;eth2;35;192.168.140.114;b8:ac:6f:8d:ac:b6;Vmnic1;00:50:56:5d:ac:b6;; Gordon;eth3;254;192.168.33.10;b8:ac:6f:8d:ac:b8;Vmnic2;00:50:56:5d

Powershell: Doubled double quotes in inline expressions

与世无争的帅哥 提交于 2019-12-24 02:06:08
问题 Please could anyone explain me why the following happens: "Fancy string - Hor""ray" # outputs correctly (only one double quote): Fancy string - Hor"ray 'Hor"ray'.Replace('"', '""') # outputs correctly (two double quotes): Hor""ray "Fancy string - $('Hor"ray'.Replace('"', '"'+'"'))" #outputs correctly (two double quotes): Hor""ray "Fancy string - $('Hor"ray'.Replace('"', '""'))" # outputs INCORRECTLY (only one double quote): Fancy string - Hor"ray In my opinion, developers would intuitively

Writing a hex escaped char in Powershell

这一生的挚爱 提交于 2019-12-23 15:23:57
问题 Is there any way to write something like this in Powershell? (Linux would be with Perl) char foo = '\x41'; I need to input some non-printable characters to one of my programs 回答1: You can do it by casting an int to char . With a decimal number : $foo = (65 -as [char]) And from hexa : $foo = (0x41 -as [char]) Both will set $foo to A 回答2: Short form is: $foo = [char]0x41 来源: https://stackoverflow.com/questions/24626455/writing-a-hex-escaped-char-in-powershell

Get-ChildItem equivalent of DIR /X

坚强是说给别人听的谎言 提交于 2019-12-23 14:22:10
问题 How do I show a directory listing in 8.3 notation in PowerShell? 回答1: You can use WMI: Get-ChildItem | ForEach-Object{ $class = if($_.PSIsContainer) {"Win32_Directory"} else {"CIM_DataFile"} Get-WMIObject $class -Filter "Name = '$($_.FullName -replace '\\','\\')'" | Select-Object -ExpandProperty EightDotThreeFileName } Or the Scripting.FileSystemObject com object: $fso = New-Object -ComObject Scripting.FileSystemObject Get-ChildItem | ForEach-Object{ if($_.PSIsContainer) { $fso.GetFolder($_

Script to export to excel

非 Y 不嫁゛ 提交于 2019-12-23 12:27:27
问题 I Have below script:-- looking for help to convert the output to excel format $servers = get-content “c:\list.txt” foreach ($server in $servers) { $server $command = “quser /server:” + $server invoke-expression $command } when executed getting in below format the output. server1 USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME Vdw231 ica-tcp#8 7 Active . 11/5/2012 10:40 AM Vdw232 ica-tcp#60 16 Active 16:18 11/5/2012 2:22 PM Vdw233 ica-tcp#71 3 Active . 11/6/2012 6:10 AM Vdw234 ica-tcp#72 1

Find duplicate values in one of the two columns in a text file

不羁岁月 提交于 2019-12-23 11:39:10
问题 I have a text file with two values in each line separated by a space. Now I want to know duplicate values in one of the columns. Is it possible to achieve this using Windows powershell. Given a text file: Apple Fruit Banana Fruit Carrot Vegetable Desired output is: (I want to find duplicates in second column) Fruit 回答1: You could use the Import-CSV cmdlet and specify a whitespace delimiter to easy get access of the second column. Then you can group the objects using the second column and

Usage of powerShell.AddCommand

青春壹個敷衍的年華 提交于 2019-12-23 10:47:08
问题 I would like to execute this event using c#. Get-WinEvent -Path 'D:\Events\myevents.evt' -Oldest | Select-Object -Property * | ForEach-Object {$_ | ConvertTo-Json} I have written upto path = "D:\\Events\\myevents.evt"; var powerShell = PowerShell.Create(); powerShell.AddCommand("Get-WinEvent"); powerShell.AddParameter("Path"); powerShell.AddArgument(path); powerShell.AddParameter("Oldest"); powerShell.AddCommand("Select-Object"); powerShell.AddParameter("Property"); powerShell.AddArgument("*"