Quantcast
Channel: PowerShell
Viewing all 15370 articles
Browse latest View live

Get customized distribution list report in Exchange By Power-Shell

$
0
0

Hi there!

I am trying to obtain report for distribution lists in particular OU, and the result show showing the below Columns:

( DL name, OU, AcceptMessagesOnlyFromSendersOrMembers, ManagedBy, Count )

NOTE: need to get the (AcceptMessagesOnlyFromSendersOrMembers) result by the user displayname not canonical name

Thank you in advance



xaml WPF datagrid issue coloring row on given value

$
0
0

Hello

I would like to color the row only if the ping status is "OFFline"

I try many tests but actually I'm blocking

if my last computer to ping is offline all my rows are colored in red

if my last computer to ping is online all my rows are colored in green


I don't want to use xaml bindings because the colums of the datagrid change at each function button

If someone could help please :-)


Here is the code of my button :


Powershell
$ui.BTN_Ping.Add_Click({$ui.Grid_Output_Computer.Dispatcher.invoke([action]{$ui.Grid_Output_Computer.Clear()})($ui.LV_Selected_Computers.Items).name|foreach{$status="";$t="";$IP="";$t=Test-Connection$_-count1if($t){$status="ONline";$ui.Grid_Output_Computer.RowBackground="green"}else{$status="OFFline";$ui.Grid_Output_Computer.RowBackground="red"};if($t)...

Powershell: Write-Output in Function with Return Value

$
0
0

I've narrowed down a problem I've asked about before here so hopefully this will bring about the best answer. My issue is that I need to use Write-Output in many places throughout my script however it will not always work. This occurs when I attempt to use Write-Output in a function that returns a value. So, here are two examples.

This would work:

Powershell
functionhello{for($i=0;$i-lt5;$i++){Write-Output"Hello World $i"}}hello#OutputHelloWorld0HelloWorld1HelloWorld2HelloWorld3HelloWorld4

This would NOT work;

Powershell
functiongetOut($number){if($number-eq1){Write-Output"Uh oh"$retVal="false"}else{Write-OutputWoo$retVal="true"}return$retVal}functionhello{$boolQ=0$outPut=getOut$boolQWrite-Output"Finished!"}hello#OutputFinished!

Now, I'm still unsure to the exact cause but...

Powershell: Write-Verbose "" - Verbose without "Verbose: " at the start

$
0
0

The output of

Powershell
Write-Verbose"I'm sorry for yet another silly Powershell problem and I swear I've searched Google"-Verbose

should be this:

Text
Verbose: I'm sorry for yet another silly Powershell problem and I swear I've searched Google 

And it is when I use it however, I really want to get rid of the start.

I've been using Write-Output for everything but as it turns out, Write-Output can break things when used within functions that will return something. To fix this, Write-Verbose was the obvious option. A completely separate stream for my output. What could go wrong? Well, basically I like keeping my log clean and I really really really do not want to see "Verbose: " at the start of every single line.

My question to you is, can I possibly turn this off?

Using Get-Credentials but need to make Windows forget again

$
0
0

Trying to get something working on a meeting room PC that is logged in with a basic generic user, Shows the room calendar / details.

Users need to be able to come along and access there files for presentations etc,

Rather than have them log in to the PC with there credentials im putting together a PS script to map there drives then clean up when they finish,

Script starts with Get-Credential which puts up the prompt for them to supply username \ password, it then checks which drives they should have mapped against AD and maps them using net use.

This is working fine, drives appear in Explorer, Users can access files.

Now i need to clean up the session when they are finished,

A reset script can remove the drive mappings from Explorer but Windows is keeping the supplied credentials cached and allowing access to shares based on this,

Credentials...

powershell script to start server for specific user

$
0
0

Hello experts,

We have a service that need to start for particular user, we want that service to run when user log off as well.

how to achieve this.

Regards

DJ

Output to Log File

$
0
0

Community,

First, I want to say that I got a lot of help from you and because of that, I completed the project with a high review and they are loving what I am doing. This is a new job so this really helped. So again, thank you. I have learned so much about PowerShell through you guys and doing this project, I am attacking other things which is great.
I do have one question about how to get the log file to output correctly. There is a column that has a list of items. How can I get them to be separated by a comma but in a text file is filled with comma's. so I would need quotes around it.
I have tried the following:
Powershell
$Groupnewname="'$($Group-join"','")'"
The problem with that is, that it will put quotes around the correct places but the groups are not separated by a comma. So for example:...

Favorite Powershell Editor

$
0
0

I've personally grown used to PowerGUI though before that I was using the ISE. I think that VS-Code is great too but I generally like one that will be able to give me some description on the commands I'm using. With GUI, you can right-click and ask for a description. It gives the standard detailed description but in a nice formatted way. One of my favourite things about GUI is the ability to compile your scripts into a .exe. I can't really decide on a favourite but I'm trying to get myself used to VS-Code as of now. Though I like GUI, I really do miss the Power of ISE and VS Code. GUI is filled with annoying bugs and I doubt DELL will fix it. My favourite look has to be VS-Code with the good old dark theme. You have to admire the ability to view variable values without running a script and also the warnings for issues in your code....


Need to extract lines from a log file

$
0
0

OK, so let's be clear. I don't really have a programming background but I've muddled my way through creating a few PowerShell scripts to get some jobs done. Now I've got a much more complex thing that I've been asked to do, and I'm not sure how to go about it.

What I need to do is search a log file (it's a simple text file) for the word error and then pull about 5 lines previous to that error and put them in an email.

If outputting to a new text file and sending that file as an attachment is easier that's perfectly acceptable, I just need to be notified if a specific process outputs an error in the log file.

Is this possible?

Wondering how to put givenName and sn into email subject

$
0
0

Hey!

So I am attempting to automate some tedious tasks I do. One of the tasks is user deletions. When we delete users one of the sub-tasks is send an email to a group. I have everything funtioning how I would like, except for the givename and surname.. When I try to add the givename and surname to the subject it displays as is "User Deletion - @{givenName=Test} @{sn=User}"

Here is some of the code:

Powershell
$user=Read-Host"Enter username"$admin=Read-Host"Enter your initials"$userFirst=Get-ADUser$user-PropertiesgivenName|SelectgivenName$userLast=Get-ADUser$user-Propertiessn|Selectsn$userTitle=Get-ADUser$user-PropertiesTitle|SelectTitleSend-MailMessage-To"deletionggroup@domain.com"-From"adminemail@domain.com"-Subject"User Deletion - $userFirst $userLast"-Body"$userFirst $userLast – $userTitle,...

Help - Generate report of outgoing emails from specific user

$
0
0

Hi all.. I'm not a PS guru and can really use your help. I have this script that I am trying to modify to include all the emails sent from a specific mailbox over a date range. Basically our sales manager wants to see who our sales associate is emailing. I found this script here on the spiceworks community forums. The code that starts at $recipients1 works from the PS command line, but I cannot get it to insert into the body of the email. After that is resolved, I then want to filter out outgoing email that are to my works domain accounts. Any help would be greatly appreciated.

Text
#################################### # Exchange 2010 send/receive weekly report generator # Created by: Eric Schewe # Created on: 2014-10-02 # #################################### # Summary: # This script will count the unique message IDs send and recieved...

Updating AD user attributes via Powershell

$
0
0

I'm trawling through the many previous questions too, but purely for selfish reasons, asking might get me a solution quicker.

Our AD once upon a time was not our primary directory service - we had Novell eDirectory. When we migrated way way back, we didn't carry across attribute data for users (phone number, job title etc). This info was then kept up to date in a simple database instead that fed our Intranet.

Now I want to put that info back in AD.

I've used a command to get my CSV from AD, which I then want to modify and then push back to AD. The export is easy -Get-ADUser -Filter * -SearchBase "OU=xx,DC=xx,DC=msft" -Properties * | Select -Property SamAccountName,CN,Country,GivenName,sn,EmailAddress,UserPrincipalName,MobilePhone,OfficePhone,Title | Export-CSV "C:\\ADusers.csv" -NoTypeInformation -Encoding UTF8

I need help getting it back...

Get-ADGroupMember - Exported CSV is blank

$
0
0

Hey Everyone,

I am trying to export a list of Members within an AD Group and export it to a CSV File now, I've used this before and its worked however upon this Group its simply exporting a blank CSV with no data in it.

Any help would be appreciated :)

$UserCredential = Get-Credential
Import-Module ActiveDirectory
$defaultFolder = "C:\psinfo"

Get-ADGroupMember -Identity "GRP_FS_DXF_RESOURCEPLANNER_RW" | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled } | Export-Csv "C:\PSScripts\CSV Exports\Rp.csv" -NoTypeInformation


Updating DisplayName in Active Directory

$
0
0

Hi All,

Hoping someone can help. I am pretty new to Powershell so knowledge is limited on it currently, is there anyone out there who has a script which can update the Display Name of an AD account so that it gets the following data FirstName, LastName + (student) i am currently trying to update a bunch of student accounts to show the display name this way as our AD syncs with Office 365 and some students have e-mail access however I need to clearly show that this e-mail account is a student e-mail account in the eyes of the global address list.

Any help will be appreciated.

Many Thanks,

Chris.

Windows Administration with PowerShell: Just Enough Administration

$
0
0

Hey everyone!

Just wanted to share the code referenced in a recent how-to I posted in a readable format.https://community.spiceworks.com/how_to/159692-windows-administration-with-powershell-just-enough-ad...

Powershell
#Wizardry section$path=""New-Item-ItemTypeDirectory-Path"$path\JEA"New-Item-ItemTypeDirectory-Path"$path\JEA\Roles"New-Item-ItemTypeDirectory-Path"$path\JEA\Sessions"New-Item-ItemTypeDirectory-Path$path\JEA\Transcripts#Role CapabilitiesNew-PSRoleCapabilityFile-Path"$path\JEA\Roles\HelpDesk.psrc"VisibleCmdlets='Get-NetIPConfiguration',@{Name='Restart-Service';Parameters=@{Name='Name';ValidateSet='amagent','spooler'}},@{Name='Start-Service';Parameters=@{Name='Name';ValidateSet='amagent','spooler'}}#Session ConfigurationNew-PSSessionConfigurationFile...

Powershell Script for Monitoring Live Log files

$
0
0

Looking for anyone that might have or guide me to a PS Script for monitoring a live log, need to alert after 'X' Minutes of inactivity.... Thanks

Script Help: If more than one USB Drive inserted, then...

$
0
0

Trying to get PowerShell to prompt to select which Flash drive, ONLY if there are more than one inserted, else just skip the rest of this portion of the script. Can't figure out what I need to do... I tried the if ($USB -gt 1) but it's always true... even when there is just one.

Powershell
$USB=gwmiwin32_diskdrive|?{$_.interfacetype-eq"USB"}|%{gwmi-Query"ASSOCIATORS OF {Win32_DiskDrive.DeviceID=`"$($_.DeviceID.replace('\','\\'))`"} WHERE AssocClass = Win32_DiskDriveToDiskPartition"}|%{gwmi-Query"ASSOCIATORS OF {Win32_DiskPartition.DeviceID=`"$($_.DeviceID)`"} WHERE AssocClass = Win32_LogicalDiskToPartition"}|%{$_.deviceid}if($USB-gt1){$USB|Out-GridView-Title'Which USB Drive is yours?'-PassThru}#else just skip...

ServiceUI.exe Exiting with [-1]

$
0
0

Hello everyone,

I hope some one has an answer for my question. I have been trying to install shared printers for our domain users remotely without interacting with the users. I am also trying to run a PS script on user level to clear the credential manager of logged in users. During my search in the internet I found a tool from Microsoft named ServiceUI.exe , so I tried the following:

1. I copied ServicesUI.exe to the system file of the target computer.

2. I created a PS named test.ps1 and copied it to a Temp folder on the Target computer.

3. I used Invoke command from my computer to run the serviceUI.exe on the remote computer and execute the test.ps1 file on the remote computer

Powershell
$computerName="something"Invoke-Command-ComputerName$computerName-ScriptBlock{ServiceUI.exe-process:explorer.exe%SYSTEMROOT%\System32\...

Disable USB HUB Allow Computer Turn Off Save Power

$
0
0

I remotely manage thousands of Windows 10 Pro terminals. Each terminal has a USB Printers plugged in, and when Power Save Mode is enabled they will stop working.

I am looking to compose a CMDLET that automatically looks for all USB Hubs/USBRoot Hubs and disables this feature. I did findthis article, but it does not work. Spent a bit of time searching, and have hit a wall.

  • I'm expecting to write the script myself, but I'm just not sure where to start.

Does anyone have a working example that I can review to learn from?

What I Script to Do:

  • Looks at all USB hubs Power Management Status
  • Ifsave power is turned on, disable. Otherwise go to next.

Pretty straight forward. This would save me a lot of head

USB Root Hub Power Photo


new user script with MFA enabled

$
0
0

Hi all

I have a new user script that creates users based off a csv. AD account, on prem mailbox and then migration to office 365 takes place.

This works however when I enable MFA and use this account, it fails.

Can anyone take a look to see if I can modify any of the below? I have added the sections of code which import the relevant areas for the script to run which require logins

Powershell
DefineADServer$ADServer='adserver'#Get Admin account credential$GetAdminact=Get-Credential-Message"Enter in your Domain Admin account"######## Get Admin account credential for Exchange Online server$UserCredential=Get-Credential-Message"Enter in Admin Credentials for Azure AD Connect - Full email address required"# The Azure AD Connect Server Name$AADConnectServer='adconnect'# Import AD and Exchange$ExchangeServer=...
Viewing all 15370 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>