powershell-3.0

PowerShell Remoting $Using variable scope

倖福魔咒の 提交于 2019-12-28 04:15:07
问题 I have folder c:\test where I have three files: “file1”, “file2”, “file3” Following script: $remoteSession = New-PSSession -ComputerName localhost $folder = "c:\test" $exclude =@("c:\test\file1","c:\test\file2") Invoke-Command -Session $remoteSession -ScriptBlock { #$Using:exclude Get-ChildItem -Path $Using:folder -recurse | Where {$Using:exclude -notcontains $_.FullName} } Remove-PSSession $remoteSession Gives the result: However, if I uncomment “$Using:exclude” I get the result: Suddenly

Powershell ConvertTo-json with embedded hashtable

前提是你 提交于 2019-12-28 02:03:47
问题 I'm having a problem with ConvertTo-Json and was trying to understand the behavior and/or what I'm doing wrong. Consider this sequence of commands: $val=@{ID=10;Config=@{ID=11;Config=@{ID=12;Config='end'}}} ConvertTo-json $val ConvertTo-json @($val) The first conversion gives this output: { "ID": 10, "Config": { "ID": 11, "Config": { "ID": 12, "Config": "end" } } } The second conversion gives this output: [ { "ID": 10, "Config": { "ID": 11, "Config": "System.Collections.Hashtable" } } ] It

Access Denied - get-wmiobject win32_service (Powershell)

匆匆过客 提交于 2019-12-25 09:44:23
问题 11/13/2013 11:35:37 TRCW1 using local computer 11/13/2013 11:35:37 TRCE1 System.Management.ManagementException: Access denied at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext() at Microsoft.PowerShell.Commands.GetWmiObjectCommand.BeginProcessing() Code (inside a loop of server names): $error.clear() #clear any prior errors, otherwise same error may repeat over-and-over

How do I set-location ad: to a different active directory domain with Powershell

不问归期 提交于 2019-12-25 04:09:55
问题 I have the Active Directory module installed on my Windows 7 workstation using PowerShell 3 and when I use "Set-Location AD:", it is using my current domain. Is it possible to set my base location to a different domain? Import-Module ActiveDirectory Set-Location AD: Get-ChildItem (shows current DC info) I would like to switch to a different AD server. 回答1: You can try this. Assuming your domain name is fabrikam.local Import-Module ActiveDirectory New-PSDrive -Name ADFAB -PSProvider

check csv for blank fields and write output if exist blank

╄→尐↘猪︶ㄣ 提交于 2019-12-25 03:26:39
问题 This is a csv example: 1- 2018-11-07,hostname-184,IP_INFO, 10.2334.40.334, 255.255.255.0, 2 - 2018-11-07,hostname-184,IP_INFO, 334.204.334.68, 255.255.255.0, 3- 2018-11-07,hostname,7.1.79-8,IP_INFO, 142.334.89.3342, 255.255.255.0, 4- 2018-11-07,hostname,7.1.80-7,IP_INFO, 13342.221.334.87, 255.255.255.0, 5- 2018-11-07,hostname-155,IP_INFO, 142.2334.92.212, 255.255.255.0, 6 - 2018-11-07,hostname-184,IP_INFO, , , 1 7- 2018-11-07,hostname-184,IP_INFO, 10.19334.60.3343, 255.255.255.0, so how can i

Create Blank Access Database Using Powershell

自闭症网瘾萝莉.ら 提交于 2019-12-25 02:43:40
问题 Normally I'd research the topic I need for a day or 2 and then ask here, but I've been struggling to find anything at all about this topic. Does anyone know how to use PowerShell (V3) to create a new Access 2010 MDB file, with a defined table and column headings? Thanks for any guidance. 回答1: Found some! Just for interests sake for anyone checking, here is the code: Function Create-DataBase($Db){ $application = New-Object -ComObject Access.Application $application.NewCurrentDataBase($Db,10)

Fetching volume number in PowerShell

久未见 提交于 2019-12-25 01:35:53
问题 I am running PS cmdlet get-customcmdlet which is generating following output Name FreeSpaceGB ---- ----------- ABC-vol001 1,474.201 ABC-vol002 2,345.437 ABC-vol003 3,147.135 random-value 4,147.135 I want to capture 003 from the highest volume number ABC-vol003 I also want to ignore random-value and only want to consider the values which have vol in it get-customcmdlet | select Name Name ---- ABC-vol001 ABC-vol001 ABC-vol001 random-value Here, I want 003 to be variable based upon highest

Can you import .CSV data into SQL Server using commands from Powershell 3 or 4?

*爱你&永不变心* 提交于 2019-12-24 19:37:01
问题 Is there a Powershell script for PowerShell version 3 or version 4 that allows you to import values from a .CSV file into a SQL table? I'm trying to figure out whether I can script a PowerShell job to import data, using enterprise Servers running older versions of PowerShell (It would be preferred if this can be done without importing any additional modules) (Nice to have, but not necessary) Also interested to know if there's a way to report the success or failure of that job, to a log file?

powershell - execute cmdlet remotely with php

…衆ロ難τιáo~ 提交于 2019-12-24 17:50:14
问题 I need to get status of service for simple monitoring tool. There is no problem to get status locally, but when I try to get status of service on remote computer like this: <?php $output = shell_exec('powershell.exe "(get-service Webclient -computername server1).Status"'); echo "Webclient: $output "; ?> I get nothing. WinRM on server1 is set to receive requests and to allow remote access. The Get-Service on remote server1 works fine in console window. This works (locally): <?php $output =

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