Powershell

18K

Solutions

8K

Contributors

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

Share tech news, updates, or what's on your mind.

Sign up to Post

Morning,

When I run an export from active directory via powershell, it doesn't bring in the é letters or anything, how can I force it to do that rather than the  Eléctrico that it's giving me. Essentially it should be Eléctricos

Thanks,
Alex
0
PMI ACP® Project Management
LVL 12
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

In Exchange 2013, I am trying to set room resources so that all staff can view/review. Using powershell I enter:

Get-Mailbox | where{$_.RecipientTypeDetails -eq "RoomMailbox"}  | Add-MailboxPermission -User "Outlook Resource Administrators" -Accessright Fullaccess

I get the following error:

Get-Mailbox : The term 'Get-Mailbox' 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.
At line:1 char:1
+ Get-Mailbox | where{$_.RecipientTypeDetails -eq "RoomMailbox"}  | Add-MailboxPer ...
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
                                                           Get-Mailbox | where{$_.RecipientTypeDetails -eq "RoomMailbox"}  | Add-MailboxPermission -User "Outlook Resource Administra


Is there some type of library add-in that I need to get for power shell?
0
Hello,

I want to have access to a Windows share with Powershell Core on a Ubuntu system.

So I tried this :
$cred = Get-Credential -UserName 'domain\user'
remove-item -path //192.168.1.200/FTP/test/test.txt -Credential $cred

Open in new window


I have an error :
Remove-Item : Cannot retrieve the dynamic parameters for the cmdlet. The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform the operation again without specifying credentials.

Open in new window


Anyone can help me please ?

Thank you
0
I would like to change this part of a Powershell script so that it looks into the current folder of where it is being run from to pull the text.txt file and the attachment...

 ###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
      $splat = @{
            From =                  'email1@mail.com'
            To =                  Get-Content -Path 'text.txt'
            SmtpServer =      'mail.smpt.com'
            Subject =            $subject
            body =                  $MessageBody
            BodyAsHtml =      $true
            Attachment =      'Attachment.pdf'
      }
      Send-MailMessage @splat
###PROGRAM END###
0
I was helped by an Expert on the script below .. I didn't plan on it but my CSV has blanks on some of the attributes... can someone
assist modifying this so if there is a blank in one of the fields?

so lets say a user only needs 3 of the 4 values below updated , the script below does not work .. it only works if all four fields have values to update.

Import-CSV -Path "$env:SystemDrive\Test\temp.csv" | % {
  Set-ADUser $_.Username -replace @{'msExchExtensionAttribute24' = $_.msExchExtensionAttribute24; 'msExchExtensionAttribute25' = $_.msExchExtensionAttribute25; 'msExchExtensionAttribute26' = $_.msExchExtensionAttribute26; 'msExchExtensionAttribute27' = $_.msExchExtensionAttribute27; }
}

Open in new window

0
Hi,

Im trying to develop a script that will strip the msexchangeguid attribute from a particular OU only, once a week as a scheduled task.
Im almost there.

The first part of the script successfully identifies all users in that OU that has a non-NULL msExchangeGUID
 
Get-ADUser -SearchBase "OU=Disabled-Objects,dc=my,dc=domain,dc=com" -filter * -Properties * | ? {$_.msExchMailboxGuid -ne $null}

Open in new window


The next part of the linked script will just give me the SAMAccountNames of those users with a non-Null msExchangeGUID from the above command
Select-Object SamAccountName

Open in new window


Put the final part of setting the attribute to be Null (0000) doesnt take the SamAccountNames for action
Set-RemoteMailbox  -ExchangeGUID 00000000-0000-0000-0000-00000000000

Open in new window


Here it is in one non-functioning line.

Get-ADUser -SearchBase "OU=Disabled-Objects,dc=my,dc=domain,dc=com" -filter * -Properties * | ? {$_.msExchMailboxGuid -ne $null} | Select-Object SamAccountName | Set-RemoteMailbox  -ExchangeGUID 00000000-0000-0000-0000-000000000000

Open in new window



I also thought about i could put the output of the first two lines into a text file, that I think use as a variable
Get-ADUser -SearchBase "OU=Disabled-Objects,dc=my,dc=domain,dc=com" -filter * -Properties * | ? {$_.msExchMailboxGuid -ne $null} | Select-Object SamAccountName > users.txt

Open in new window


$users=Get-content users.txt
Foreach($user in $users){
get-aduser $user| set-aduser -clear msExchMailboxGuid
}

Open in new window


But the users.txt has trailing whitespaces after the username so the  
get-aduser $user| set-aduser -clear msExchMailboxGuid

Open in new window

looks like
get-aduser "USERNAME        "| set-aduser -clear msExchMailboxGuid

Open in new window

when it runs. It fails on the excess whitespaces.

Any help from Powershell gurus out there?
Thanks!
0
Powershell one-liner or script that can find the latest changed file recursively in a folder, per folder 1 deep.  
That might not make sense, I have shared folder "Shared", in that folder are 200 more folders, many of which may not have been used for a very long time. I'd like a list of the latest changed file (anywhere in that folder, or its own subfolders) in each of the 200 folders with the date. I hope that makes sense.
0
I would like to change this script, so that instead of hard coding in the destination email addresses, it will look into a flat txt file and use the email addresses listed in that specific file instead.


###SETUP START###
#-------DO NOT MODIFY-------#
    #Yesterdays Date
        $date = ((Get-Date).AddDays(-2)).ToString("MMM/dd/yyyy")
###SETUP END###

###USER VARIABLES START###
#-------MODIFY AS NEEDED-------#
    #Mail Subject
        $Subject = "Report: "+$date+" REVISED "
    #Body of Email
        $MessageBody = "REVISED - Report for $date. Thank you."
###USER VARIABLES END###

###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
Send-MailMessage -From 'email1@mail.com' -To 'email2@mail.com', 'email3@mail.com', 'email4@mail.com' `
  -SmtpServer 'smtp.mail.com' `
  -Subject  $subject `
  -body $MessageBody `
  -BodyAsHtml `
  -Attachment 'C:\Attachment\Attachment.pdf'
 ###PROGRAM END###

Thanks in advance for your assistance
0
The new team technician did not realize that IIS was out (and needed to be restarted) and resolved to delete the Powershell virtual directory (do not ask me why, it just did). Now when I open the Console or the Shell I can not connect to Exchange 2010. When I tried to add this virtual directory again through normal Powershell, with the imported Exchange snap, I get the error below:

IIS without Powershell VDir:
001.JPG
Error recreating Powershell VDir:
002.JPG
With IIS Metabase Explorer no more Powershell VDir configs:
003.JPG
Some way to reinstall this Virtual Directory?
0
Dear expert.

I need help with this code:
$time = ((Get-Date).Adddays(-100))
$pathlog =  "\\server\log_*"
$Pattern = "^01","^03"
$results = Get-ChildItem $pathlog -Recurse | where-object {$_.LastWriteTime -ge $time} |
	Select-String -Pattern $Pattern | 
	Group-Object Path |
	% { #Foreach-object alias
		$_.Group | Select-Object Line
}
if ($results) {
$results | Out-File D:\wei_test\resulttest.txt
$text = Get-Content -Path D:\wei_test\resulttest.txt
$text.Substring(148, 182)
$results = 1
} 

Open in new window


Now I would like to grab the Out-File result text line position  148 to 182 in each lines and show it in the powershell window.
I got a error:
 
Exception calling "Substring" with "2" argument(s): "startIndex cannot be larger than length of string.
Parameter name: startIndex"
At line:37 char:1
+ $text.Substring(148, 182)

Kinda stuck with this. thx for the help.
1
Simplify Active Directory Administration
LVL 8
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

My Exchange URL needs to be updated in a live environment to the new domain URL's.  I want to know if there is draw backs or no-no's doing this.  
Also do any of the IIS Applications need to be restarted?

I plan to use powershell to quickly loop through and change all the URL's I need to match my new SSL cert.  
I am using a SAN Cert issued by GoDaddy that includes 4 of the new addresses plus one old URL.


Set-ActiveSyncVirtualDirectory                                                                          
Set-AutodiscoverVirtualDirectory                                                                              
Set-EcpVirtualDirectory                                                                                      
Set-OabVirtualDirectory                                                                                      
Set-OwaVirtualDirectory|                                                                                                                                              
Set-WebServicesVirtualDirectory                                                                              
Set-WebVirtualDirectory
0
Hi Folks,
I have a http index i need to download where it looks something like this
structure.JPG
i do have created a script that will download single files..., but not along with the structure, is there any way to do so, or a better cmdlet?
i wish xcopy would handle websites...

Import-Module BitsTransfer
$URL = "http://website"
$OUTPUT = "C:\Folder"    
$clock= Get-Date

write  "starting time"  $clock
write " " 
Start-BitsTransfer -Source $URL -Destination $OUTPUT 
write " "
write "ending time" $clock

Open in new window


Thanks for looking
0
I'm trying to use Powershell to Base64 encode an mp3 audio file (for uploading via API call), but for some reason the resulting Base64 encoded text isn't right. Here is my code:

$recording="c:\myfile.mp3"
$fileContent = Get-Content $recording -Encoding UTF8
$fileContentBytes = [System.Text.Encoding]::UTF8.GetBytes($fileContent)
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
$fileContentEncoded | set-content ("c:\output.b64")

Open in new window


I compare my resulting text from this script with the resulting text from one of the free online base64 encoders (which I know is correct), and I get a different string of text.

Can anyone help me?
0
Hello Experts - I am trying to export a list of domains that a user has on the Outlook spam list but the output from this command is truncated after the first few entries:

Get-MailboxJunkEmailConfiguration -Identity user@domain.com | Out-File C:\filename.txt

What additional switches do I need here so the output is not truncated?
0
Hi EE

Can someone help me so I can also update three other attributes similar to the script below ?
CSV with the four columns .
SamAccountName,msExchExtensionAttribute24,msExchExtensionAttribute25,msExchExtensionAttribute26,msExchExtensionAttribute27




Import-CSV -Path "$env:SystemDrive\Test\temp.csv" | % {
  Set-ADUser $_.Username -replace @{'msExchExtensionAttribute24' = $_.msExchExtensionAttribute24}
}

Open in new window

0
I need to update the telephone number field in the user ADUC from the IPphone field with powershell . The ipphone  has this format 000-0000 the telephone field has this format 000-000-0000 I need to include the area code .

The ipphone is already populated so it needs to get that number and place it in the telephone field but with an area code in front of it so that all 10 digits are populated
Thank you
0
Hi,

Simple question. In PowerShell ISE every times I type a cmd the PowerShell suggests me a list of paramaters or functions automatically. Is there something similar in normal PowerShell. I'm tired to search the syntax in the web...:-)

Thanks
0
Hi,

 Is there a way to resore contact by PowerShell in O365? Like with user I can run this cmd:

Restore-MsolUser -UserPrincipalName UserUPN

Is there such cmd for contact?
0
I need to run an update for all users in the user aduc with PowerShell to update the following fields.
The PowerShell script needs to read the information from a csv file that will then go to ad and update the information

I need to key off of the user samaccountname and update the following :
Department
Title
Manager
Telephone
Office
Address
city
state
zipcode
0
Redefine Your Security with AI & Machine Learning
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

Let's say I'm a domain Admin from domain A and domain A have a trust wit domain B, C and D. So I need to create a group with my domain A credential for domain B, C and D.
How can I do it ?
0
I need a script or command to create a local user and add it to the local administrator's group on remote machines.  Can this be done?  I can not do this via GPO because it's blocked so I need a back door.

I have this so far net user /add account password
net localgroup administrators account /add
0
I pieced together a PowerShell script that is triggered (via Task Scheduler) every time the computer restarts.

The script will do the following:
1. Find a csv file located in a specific directory
2. Rename the file by appending a time/date stamp to the end
3. Move that file into an archive folder

During the day a software application automatically creates a new csv file. So next time the computer reboots, it repeats the steps above.

4. Final step - the script also looks in the archive folder and deletes any files which are > 7 days old.

Sometimes (not all the time) when the computer restarts and the script runs, it completes steps 1 and 2 but not step 3.
And so what this means is the csv file is renamed but the script did NOT move it into the archive folder.

Why?
I open the script in PowerShell ISE and run the script manually and I see the reason why:
A file with that name already exists in the archive folder.

How can that happen if the file name is always dynamically renamed using a date/time stamp (down to the second).

Turns out the variable which is assigned the value of Get-Date is not updated.
It still contains the old time.

Why does this happen if the very first thing I do in my PowerShell script is this:
$rightNow = Get-Date

I know it's not best practice to assign the current date and time to a variable and obviously the variable is not going to update itself as every second goes by. That's fine. I don't need it to. What I DO expect …
0
We require to identify what SMB version is being used on all client machines on the network (Win 7 and 10).

A PowerShell script to extract the SMB version of all clients (single domain) and place the output into a CSV.
0
I am wanting to create security group for filtering purposes.

They do not exist yet and I am wanting to create them.

I would like to get all my AD user and select the value of the "Division" field.

With that field I'd like to add them to a group in an OU called "SafetyNet"

If the group that matches the name of their division exist - they would be added to that group. If not, the group would be created and then they would be added.

I imagine it would look something like this:



$users = get-aduser -properties * -filter {enabled -eq '$true' -and division -ne '$null'}

foreach ($user in $users)

{add-adgroupmember -Identity {

    Get-ADGroup $user.division 
    (if (unsure what goes here))

{}

else {
    new-adgroup -name $user.division -SamAccountName $user.division -GroupCategory Security -GroupScope global -path OU=safetynet,DC=smh,DC=org
}


}}

Open in new window

0
Hi, I need help to code this in PowerShell:

$Users = Import-Csv "C:\temp\ExchangeMailboxes.csv"

ExchangeMailboxes.csv contains these info: SamAccountName,Mail

How can I get the mail info in ExchangeMailboxes.csv and the result of this cmd:

$Users | where {$_.domainFQDN -eq "mydomain"} | % {Get-ADUser -Identity $_.SamAccountName -Properties admindescription} | Select Name,SamAccountName,AdminDescription,Enabled

How can add mail info in the below cmd. So at the end I should get: Mail,Name,SamAccountName,AdminDescription,Enabled

Thanks
0

Powershell

18K

Solutions

8K

Contributors

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.