powershell-2.0

Converting date time format in PowerShell

谁说我不能喝 提交于 2019-12-24 10:44:11
问题 How do I convert the following date into the dd/mm/yyyy format? Tue Aug 4 17:05:41 2015 I tried multiple things and options, but no luck. $a = Get-Date -UFormat %c (Get-Date $a).ToString("ddMMyyyy") This dateformat was found in a log file and my system datetime format is dd/mm/yyyy. I am trying to do a comparison between them. So, I need to change the date time format. 回答1: The answer from @jisaak is almost spot on, except for the fact that the extra padding space in front of the date

Powershell Progress Bar

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 08:48:29
问题 I'm new to Powershell and am having a problem getting a progress bar to work with a foreach-object loop (If it is even possible) Thanks to Chris below is what I have so far, my problem here is that the progress bar gets to a point and then I get error: The 101 argument is greater than the maximum allowed range of 100: $FolderList = Get-Content C:\Folders.txt $i = 0 foreach( $Folder in $FolderList ) { Write-Host $Folder Get-ChildItem $Folder -Recurse *.pdf | foreach-object{ $fileCount = (Get

set “the following user or group can join to a domain” after creating the computer

谁都会走 提交于 2019-12-24 07:04:54
问题 I have come across an issue where a user can create a computer in AD, nobody else can join the computer to the domain except for the user who created it in AD. When creating the computer in admin tools there is an option titled "the following user or group can join to a domain" if this is set to a certain group then that group can join to the domain. When I look at the properties of a computer in the admin tools I cannot find this setting anywhere. Where do I find this setting? Can this

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 ----- ---------------

How do find out short name of domain I'm in?

泪湿孤枕 提交于 2019-12-24 04:07:10
问题 I want to return the short name of the domain the computer I am running on. I do not want the $env:USERDOMAIN because that is the domain the user is logged on to, which could be different to the domain the machine is in. If I do (gwmi win32_computersystem).Domain This gets me the FQDN, but I want something similar to return the short name (NETBIOS name?). I am currently parsing the FQDN, but I know this will lead to bugs later. I don't have the Active Directory module installed, and company

Calculate total seconds from string in format “HH:mm:ss,fff”

我是研究僧i 提交于 2019-12-24 02:39:09
问题 In PowerShell V2, I want to calculate the total seconds and milliseconds of a given string. My string is 00:03:56,908 and the desired output would be 236.908 My working, but awkward code is $a = "00:03:56,908" $a = [datetime]::ParseExact($a,"HH:mm:ss,fff",$null) [string]($a.Hour*3600 + $a.Minute*60 + $a.Second) +"."+ [string]$a.Millisecond Is there a smarter / shorter way to achieve this? All I found was .totalseconds from a TimeSpan object. But this code was even longer in my attempt 回答1:

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 Hash Table to HTML

雨燕双飞 提交于 2019-12-24 01:54:46
问题 I am trying to write a very simple Powershell script that checks files in a location and then decides if any are older than 90 days. Easy but it would be good if I can use PS's send-mailmessage cmdlet to use the hash table I have created and accept the contents formatted into HTML to be use in inside a pre build email template. I have put together the following script (with the table part lifted from another post on StackOverflow - http://stackoverflow.com/questions/11263538/powershell

Embed VBS into PowerShell

Deadly 提交于 2019-12-24 00:39:01
问题 We have an application here that dumps data into a CSV, which is then used by another script. In the previous iteration of the application, one of the columns was "user_name" and contains user IDs. That is still there, but it now appends "_company" to the user ID, so instead of the user ID "tim" it is now "tim_company" in the column. We are looking to strip the company off, and I thought the best way would be to embed some VB into the existing script as a function, like this site suggested:

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