Hello All,
Im trying to find all domain computers with a specific error id, Is there is away to to find\ search all domain computers who have a specific error\ warning idFind Domain PCs with a specific error id
Clone Windows 10
convert .eml to .msg
I have 500000 .eml files that needs to be converted to .msg file and save in local folder.
I want to know if we have any powershell command to do so?
Or any other efficient method to achieve this??(C#)
PS: Dont want to use third party converters.
Menage Errors
Hi all,
I'm writing a script and I'm trying to manage errors occurring wiht this command
Try
{
New-MoveRequest -Identity $Member.UserPrincipalName -Remote -RemoteHostName $RemoteHostName -TargetDeliveryDomain $TargetDeliveryDomain -RemoteCredential $O365RemoteCredential -BadItemLimit 1000 -AcceptLargeDataLoss -BatchName $O365BatchName
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
}
Debugging the script when I try to execute this command I've this output:
WARNING: When an item can't be read from the source database or it can't be writ
ten to the destination database, it will be considered corrupted. By specifying
a non-zero BadItemLimit, you are requesting that Exchange not copy such items to
the destination mailbox. At move completion, these corrupted items won't be ava
ilable in the destination mailbox.
Target user 'user' already has a primary mailbox.
+ CategoryInfo : InvalidArgument: (username@domain.net:Mai
lboxOrMailUserIdParameter) [New-MoveRequest], RecipientTaskException
+ FullyQualifiedErrorId : 571F77AD,Microsoft.Exchange.Management.Recipient
Tasks.NewMoveRequest
+ PSComputerName : casserver.domain.net
Why this error is not saved in $PsInfo ($_) variable ?
I would like to write it in a log file
I hope to have correctly explained my issue.
Thanks
Regards
Creating users via Powershell
Hi
First post here. I'm writing a script that does 2 things
1. Create an AD User account
In fact I have this already, it takes a list of users from a CSV file and creates an on prem AD account for each user
However it then needs to do the following
2) Sleep for a predetermined length of time to allow for the AD account to become synchronised up to Azure AD via Azure AD Connect
3) Assign an O365 Business Essentials licence and then create an O365 mailbox for this new user.
Things to note
- Single AD domain
- Email services are cloud only, there is no hybrid or on-prem exchange, nor has their ever been. This is a brand mew company
- As such there has been No AD Prem and nowhere is there an installed Exchange Management Tools/Shell. Everything messaging related needs to be done against the 365 Powershell
- It would be nice to have a single script that does this end to end, but if I need two scripts then that will be OK, especially if they can both work from the same .csv file
Any pointers here would be great
Update: Should have said I'm happy to write it, but just need to know if what I want to do is in fact feasible. For instance I think I'll need to have 2 sessions running, once to AD and another to O365. Can you do that in a PowerShell script?
and presumably the second session will just use Enable-Mailbox, rather than New-RemteMailbox which I think is useful when a hybrid environment is in place.
Thanks all
Mike
PowerShell doesn't recognize cmdlet when run from own code
Situation: I'm trying to zip some files from C++ which, as we all know, doesn't have any built-in support. The first solution, IShellDispatch, only works with administrative privileges (I suppose corporate IT screwed something up) and using an external library is out of question due to said corporate IT.
So I'm trying to call PowerShell to do the job for me.
The following code works fine when run from a CMD console or Run dialog
powershell -command "&{compress-archive 'InFile.1','InFile.2' OutFile.zip -force}"
I get what I expect, an OutFile.zip with both files contained. But when I run the following C++ code
wstring Parameters = L"-noexit -command \"&{compress-archive 'InFile.1','InFile.2' OutFile.zip -force}\""s; ShellExecuteW(nullptr, nullptr, L"powershell", Parameters.c_str(), nullptr, SW_SHOWNORMAL);
I get a PowerShell telling me
The term 'compress-archive' is not recognized as the name of a cmdlet,function, script file, or operable program. Check the spelling of the name, orif a path was included, verify that the path is correct and try again.
which I don't understand. PowerShell quotes the cmdlet which is the exact same combination of letters that works when running it from CMD or Run dialog.
Invoke-WebRequest with non supported encoding name
trying to output results to 2 seperate columns in excel
Hi I want to compare 2 users and the groups they have access to side by side in excel, if anyone had any advice it would be much appreciated
$ADGROUPS=[pscustomobject]@{
user1=Get-ADPrincipalGroupMembership username1|selectSamAccountName|sort-objectSamAccountName
user2=Get-ADPrincipalGroupMembership username2|selectSamAccountName|sort-objectSamAccountName
}$ADGROUPS|Export-CSVP:\Powershell\ADGROUP_COMPARE.CSV-NoClobber
it creates the file and creates the headers but I get no results
#TYPE System.Management.Automation.PSCustomObject | |
user1 | user2 |
System.Object[] | System.Object[] |
Set a VLAN to a VM via powershell
Hi All
I've created a script to build multiple VMs but am having trouble finding something that can add the Network VLAN to the VM.
Via the GUI - if i 'Add Network' to the VM there are multiple VLANs displayed, i select the one required (as expected)
If i run the below command:
Get-NetworkAdapter -VM computername
Output gives:
Name Type NetworkName
Network adapter 1 Vmxnet3 GAAC-Serv...
Network adapter 1 Vmxnet3 GIMC-SerB...
Can anyone help with a command so i input the NetworkName and it assigns it to the required VM?
Thanks very much
Ryan
How to pull out only certain rows from all files in a directory and write them to a file
I have a folder full of files I am looking to mine and only pick out the ones that I need to write to an output file and load into a SQL Server database. Here is a sample row:
{"timeStamp":"2018-10-01T11:35:02Z","EventID":"124211934","LogEventID":"FD8BCAA0-ACE7-11E8-969B-40E87C8EF92A","EventName":"ProofOfPlay","EventDateTime":"2018-10-01 07:35:02.5960000 -04:00","CreatedOn":"","ReflectDeviceID":"FBBDDDA1-72B0-4DE7-9637-2CCAE7CA8F45","ERPDeviceName":"8792180GROW2","ProgramID":"GROW","SessionID":"","ContentID":"","DisplayedContentIDs":"","ContentName":"lorzan_182499_02_how_ent_work_lb.zip","PageName":"Crohn's Disease","XCoordinate":"","YCoordinate":"","ScrollHorizontal":"","ScrollVertical":"","ScreenZone":"","ContentZone":"","AdType":"leaderboard","DisplayDuration":15627,"URL":"Null","IsActiveMode":"0","IsProviderSession":"0","CreatedBy":"","ModifiedOn":"","ModifiedBy":"","LocationID":"8792180","SponsorType":"","AdDisplayType":"","ContentType":"","AnalyticsID":"81012393fs5","PageID":"Passive View"}
Here is what I would like to do:
From all the files in the folder with a .log file extension pull out only the rows that contain the text "EventName":"ProofOfPlay"
Then from those lines, I want to split that output across all the input files into two files based on another field in those rows.
If the row also contains the text "IsActiveMode":"0"write it to output file called Inactive.txt
If the row contains the text "IsActiveMode":"1"then write it to output file called Active.txt
Compare all the values in a column in a csv against the contents of another csv and output to a third file
First of all, let me apologise for the horrific code contained below which badly needs repairing.
Secondly let me explain what I want to do. The file named admingroups.csv contains a single column with a header of ‘DistinguishedName’ and contains a list of admin accounts. The file users.csv contains a list of staff in a team with four columns of name,samaccountname,userprincipalname, and ‘memberof’ (this last column contains the groups of which each user is a member, and each individual’s groups are all listed on a separate row – I reformatted the original AD export which gave each user just one row for all information with all their groups stuffed into a single cell. What I want powershell to do is to check through users.csv line by line and compare every group listed against the list of admin groups within admingroups.csv. I wish to output the data in first three columns of users.csv into a new file along with manipulating the fourth column data so each group name outputs to a new column called ‘AdmGroup’ if the value matches any admin group name in admingroups.csv (if it does not it should output to the ‘StdGroup’ column). This is not working, and the columns AdmGroup and StdGroup are just filled with ‘False’ and ‘True’ values.
I *think* I need to do the following: change the format so I can output text and make the script specifically output group names; and ensure that the pipeline queries just one value at a time rather than all at once. I’d love some help with this so I can fix this and remember for the next time too.
$team='teamname'
$groupslist = import-csv -Path C:\temp\admingroups.csv
$mainlist = import-csv C:\temp\Teams\$team\users.csv
$mainlist | ForEach-Object {
if($match = "$mainlist.memberof" -eq "$_($groupslist.DistinguishedName)"){
$_
}else{($nomatch = "$mainlist.memberof" -ne "$_($groupslist)")
$_
}
}| Select-Object Name, SamAccountName,UserPrincipalName,@{n='AdmnGroup';e={$match}},@{n='StdGroup';e={$nomatch}} |
Export-Csv "C:\temp\Results\$team.groupmembers.csv"
Scripting a WCF service deployement
Dear all,
I have build a set of wcf service which are actually hosted under server 2012 IIS as Virtual application.
For now when I need to deply the update of my services, I simply copy manually my binary folder and paste it to my server virtual directory location.
But now we are implementing continous integration and deployement in our process by using TeamCity which is able to handle deployement as well using powershel script.
I have never use power shell scripting . Does some of you could help on how the script look like to to the following :
- select all files from my dektop folder \MyService
- copy all selected file to myServer folder at E:\IISService location with overwrite if exist
- Windows authentification is used on server
thnaks or help
Getting .Net Framework version using Powershell
Hi All,
I need to get the .Net Framework version using Powershell.
I need TargetFrameworkVersion not Runtimeversion.
kindly help me to get scripts.
Removing Users from Active Directory
I'm having issues removing users from active directory groups when they're on different servers than the group itself. Here's the scripts I've tried, with group "Team" being on server B.
$user = Get-ADUser "Bob" -Server "A"
Remove-ADGroupMember -Identity "Team" -Server "B" -Members $User
Also tried:
$user = Get-ADUser "Bob" -Server "A"
$group = Get-ADGroup
Remove-ADPrincipalGroupMembership -Identity $user -MemberOf $group
I can use similar scripts to add users to the group, regardless of server, plus remove users from the same server as the group. Any help offered is appreciated!
Else
The term 'else' is not recognized as the name of a cmdlet, function, script file
, or operable program. Check the spelling of the name, or if a path was included
, verify that the path is correct and try again.
The above error message kills me, but the script works, can someone help me
Help with excluding results from Get-Childitem
Hello,
I am having an issue with a PowerShell script that I am working on. This script needs to gather the files paths to all files with a specific folder recursively, but I need to exclude all files found within 3 specific folders. It works great in getting me the files paths but I cannot seem to get the exclusion to work correctly. I would appreciate any assistance that could be provided. Below is the code
Invoke-Command -Computername servername -ScriptBlock {Get-ChildItem -path "\\servername\driveletter\folder1\folder2" -recurse -file |
Where-Object { $_.LastWriteTime -ge (Get-Date).addminutes(-30) -and $_.Extension -like ".pdf" -and ($_.FullName -notcontains "badfolder1") -and ($_.FullName -notcontains "badfolder2") -and ($_.FullName -notcontains "badfolder3")} |
ForEach-Object { $_.FullName } | Out-File -FilePath D:\folder1\Script_results\Files.txt -encoding ASCII }
Thank You
Method invocation failed because [System.Object[]] does not contain a method named ‘op_Division’.
Executing the following code , I am getting the error.Please let me where I doing mistake
Code
$diskDetails = Get-WMIObject -Namespace root/cimv2 -Class Win32_LogicalDisk | Where-Object {$_.DeviceID -match “$($Arguments)” } | Select-Object -Property Size, FreeSpace, VolumeName, DeviceID
$DriveLetter = $diskDetails.DeviceID
$DriveName = $diskDetails.VolumeName
$SizeInGB = “{0:0}” -f ($diskDetails.Size/1GB)
Error
Method invocation failed because [System.Object[]] does not contain a method
named ‘op_Division’.
At line:4 char:1
+ $SizeInGB = “{0:0}” -f ($diskDetails.Size/1GB)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Division:String) [], Runtim
eException
+ FullyQualifiedErrorId : MethodNotFound
How do I create a list of all files on C drive, excluding the Windows folder?
I'm trying to create a list of all files on C drive, excluding the "Windows" folder.
(I'd need the full path and processing all sub-folders)
So far I have:
$driveLetter = 'C'
$list = Get-ChildItem -Path "$driveLetter`:\" -Recurse -File -Name | Sort-Object length –Descending
Set-Clipboard $list
Each time I've tried using "-Exclude" it returns no items.
I'm trying to make it efficient and not take ages.
Any attempt I've tried still has a long processing time as the full file list is fetched then filtered.
Anyone have an ideas for this? :D
Script to find a specific DHCP Option and listthe scope it is under
I have a Script see below it will scan and find the specific option I am looking for and list it, but it does not show me the server or scope id that it is found in, I have tried several modification to my script and have spent hours trying to fins a solution.
I tried adding another for each statement and using the -Scopeid bit does not work.
Any help you can provide is much appreciated.
$server = Import-Csv -Path "C:\Scripts\dhcpserver.csv"foreach ($Item in $server)
{
$DnsName = $item.DnsName
Get-DhcpServerv4OptionValue -ComputerName $DnsName | Where-Object OptionID -eq 67 }
getting samaccountname from an e-mail address
I need a scipt to get samaccountname from an e-mail address.
I have the script for getting samaccountname from display name
$mbxlist = Get-Content E:\Sid\Users.txtForEach ($mbx in $mbxList ) {
Get-ADUser -Filter "Name -eq '$mbx'" | Select -Property SamAccountName
}
What changes i need to make in this script to use an e-mail address instead of display name
The text file Users.txt contains display names. do i need to replace the Contents of the text files with e-mail addresses?
Please advise