powershell-3.0

Import-Pssession is not importing cmdlets when used in a custom module

梦想的初衷 提交于 2019-12-23 09:31:34
问题 I have a PowerShell script/function that works great when I use it in my PowerShell profile or manually copy/paste the function in the PowerShell window. I'm trying to make the function accessible to other members of my team as a module. I want to have the module stored in a central place so we can all add it to our PSModulePath. Here is a copy of the basic function: Function Connect-O365{ $o365cred = Get-Credential username@domain.onmicrosoft.com $session365 = New-PSSession

PowerShell + AD: Return users from within any groups in a specific OU, plus count

混江龙づ霸主 提交于 2019-12-23 05:27:37
问题 PowerShell "white belt" here, first time poster. I'll try not to lower the collective IQ of such a helpful community while I'm here! :) I'm running PowerShell 3.0 with Quest installed. My organization has an Active Directory OU with several Security Groups that all control VPN access - these were created in the days before we had naming conventions (ugh!) I'd prefer not to rely on the names by going "get me the members of X and Y and Z" but rather say "get me the members of anything in OU XXX

Compare and merge 2 csv files based on 2 first columns with possible duplicate values

ぐ巨炮叔叔 提交于 2019-12-23 02:20:32
问题 I have 2 csv files I'm asked to merge where the values from the first column match. Both files can have the possibility of having duplicate values, and if they do, a new row should be created to support those values. If no match is found, then print the value no match. Except for looking for duplicate values, I am using the following code... Function GetFirstColumnNameFromFile { Param ($CsvFileWithPath) $FirstFileFirstColumnTitle = ((Get-Content $CsvFileWithPath -TotalCount 2 | ConvertFrom

DotAll and multiline RegEx

戏子无情 提交于 2019-12-22 09:04:13
问题 i got a little trouble using Rexex in Powershell. It seems like there is a imlementation error or something. The text i want to work with is a html file, which looks like this (Example1): <span>[Mobile: %mobile% |] Phone: %telephone% [| Fax: %faxNumber%]</span> <Span> The Problem is that, caused by html editors, i also may get something like this (Example2): <span>[Mobile: %mobile% |] Phone: %telephone% [| Fax:   %faxNumber%]</span> So as you see, we got linebreaks and html escaped, fixed

PSRemoting performance overhead with get-childItem

老子叫甜甜 提交于 2019-12-22 08:25:23
问题 This completes in 2.3 minutes on LOCALSERVER: A: measure-command {$x = invoke-command {gci -recurse "C:\"}} This completes in 38.4 minutes on LOCALSERVER: B: measure-command {$x = invoke-command -comp LOCALSERVER {gci -recurse "C:\"}} Why is B so much slower? Is it because the "output is being serialized to XML and then reconstituted into objects again", as explained here, with B but not A? Or is something else going on? LOCALSERVER runs Windows 2008R2 with PS v3. In both cases $x.count is

Update Outlook inbox folder

◇◆丶佛笑我妖孽 提交于 2019-12-22 00:26:14
问题 I would like to update (sync) the inbox folder (send/receive) before running this PowerShell script that gets the e-mails, but I don't know how. Is there a way to do this from powershell? $matchString= "support@blabla.com"; $olFolderInbox = 6 $outlook = New-Object -COM Outlook.Application; $mapi = $outlook.GetNameSpace("MAPI"); $inbox = $mapi.GetDefaultFolder($olFolderInbox) $inbox.Items | where { $_.SenderEmailAddress -match $matchString } | Select SenderEmailAddress,to,subject | Format

Getting any special folder path in Powershell using folder GUID

余生长醉 提交于 2019-12-21 21:26:28
问题 I want to use a PowerShell script to automate tasks related to the user when the user logs in. Sometimes a user will have moved his Documents folder from the default location. How can I determine the location of the user's Documents folder in PowerShell with a method that will work for all special folders? I tried to use SHGetKnownFolderPath calls from PowerShell based on Lee Holmes work As pinvoke website C# sample doesn't use StringBuilder, I assumed it was not required and stripped builder

Powershell script to Upload log file from local system to http URL

依然范特西╮ 提交于 2019-12-21 17:27:26
问题 How could i upload a log file from my local system to a webpage (http://abc..) using powershell script? Thanks in advance 回答1: If you are using HTTP, try something like this: $sourceFilePath = "c:\MyLocalFolder\LocalLogFileName.log" $siteAddress = "http://192.168.15.12/DestinationFolder" $urlDest = "{0}/{1}" -f ($siteAddress, "DestinationLogFileName.log"; $webClient = New-Object System.Net.WebClient; $webClient.Credentials = New-Object System.Net.NetworkCredential("MyUserName", "MyPassword");

How to write an event log entry with structured XML data?

与世无争的帅哥 提交于 2019-12-21 12:55:17
问题 Question: How to write an event log entry with structured XML data using PowerShell? My PowerShell script writes to the Windows event log using the Write-EventLog cmdlet. Currently I use the -Message parameter to set the event log message: Write-EventLog -LogName $EventLogName -Source $EventSource -EntryType Error -EventId 1 -Message "MyMessageHere" If you look at the message using Windows EventViewer you get an XML like this: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events

How can I check if a file is older than a certain time with PowerShell?

…衆ロ難τιáo~ 提交于 2019-12-21 06:56:00
问题 How can I check in Powershell to see if a file in $fullPath is older than "5 days 10 hours 5 minutes" ? ( by OLD, I mean if it was created or modified NOT later than 5 days 10 hours 5 minutes) 回答1: Here's quite a succinct yet very readable way to do this: $lastWrite = (get-item $fullPath).LastWriteTime $timespan = new-timespan -days 5 -hours 10 -minutes 5 if (((get-date) - $lastWrite) -gt $timespan) { # older } else { # newer } The reason this works is because subtracting two dates gives you