Powershell

17K

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

This is the normal output.

FRM
MYI
MYD
MDB
MDF
NDF
BAK
LOG
TRN
FBK
LDF
EDB
CHK
pagefile.sys

Can we transpose the above output into look like this?

FRM | MYI | MYD | MDB | MDF | NDF | BAK | LOG | TRN | FBK | LDF | EDB | CHK | pagefile.sys
0
Introducing the "443 Security Simplified" Podcast
LVL 1
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

I need some Powershell help.  I need a script that will look at all AD User's Company property, and copy that value to the Department property.  Then I need to set the Company property to a new value.  I am fair with scripts, but I just can't seem to grasp Powershell syntax.  Thanks for your help!
0
PowerShell scripting issue:

Experts please assist with the following script:

  $tempDir = "\\networkserver\WORKING_DIR\Temp"
    $WorkingDir = "\\networkserver\WORKING_DIR"
    $tdrivedir = "\\networkserver\networkshare"
    $Primarycsv = "file1.csv"


    function copy-W-file($filename) {
        set-location $WorkingDir
        $date = get-date -f yyyy-MM-dd
        [string]$filenamenew = "$filename" + "_OLD_$date"
        [string]$Destination = $("$TempDir\$filename")
        [string]$WorkFileloc = $("$WorkingDir\$filename")
        [string]$Renamedpath = $("$TempDir\$filenamenew")
            
        if ($(test-path $destination) -eq 'True') {
            #Check to see if File Exists in Temp Location and Rename if Exists
            Write-Host "$filename Found in $Destination" -Fore Red;
            Write-Host "Renaming File" -Fore Yellow;   
            Rename-Item -path $Destination $Renamedpath
            #Test if File was successfully Renamed
            if ($(test-path $Renamedpath) -eq 'True') {
                write-host "Filename Successfully Changed" -Fore Green
                #check to see if File Exists in WorkingDir and if not Create it
                write-host "Checking to See if $filename Exists in WorkingDir" -Fore Yellow
                if ($(test-path $WorkFileloc) -eq 'False') {
                    write-host "$filename Does not Exist in $WorkFileLoc"
                    write-host "Copying File from Working Directory to Temp" -Fore 

Open in new window

0
hi guys

So I got some help from EE experts to run a command in Exchange shell to export all mailbox statistics/data.

One of the important things is for me to work out the LastLoggedOnTime so that I can segregate the oldest mailboxes from the actively used ones.

I ran a tool called Inactive Users Tool by Solarwinds and exported it. When I compare the last logged on time of one user from the Exchange shell formula to the data exported from the Solarwinds one, they are different. I have many users who have not logged on for years, but somehow are showing as two days ago in the Shell statistics.

Perhaps the Solarwinds tool is using the Inactive users by looking at a different attribute?


Any ideas on why that would be?

Thanks for helping
Yashy
0
Hello EE,

I wish to make use of the " write-progress" cmdlet in powershell for a script . I am building a script to restore databases . How can I add a write-progress based on the lines in the files , then create a write-host base don certain actions . For example , if my script is 5000 lines long , I wish to have a write-progress bar based on the lines . If it hits line 2000 forexample , and that is the part where it copies databases , the progress bar will state " Copying Databases" Etc .

Or , perhaps it is easier to just add a bunch of write-progress around different cmdlets . Can you do a write-progress based on sqlps? For example,
invoke-sqlcmd -query $sqlcorerestore

Open in new window

0
Can someone help me figure out how to use PowerShell to return the text string value of a P Style item in a web page?

The text string I'm trying to recover in the web page is within the p style class below.

<h3 class="ibm-h4 ibm-light ibm-padding-top-r1">Comment</h3>
<p style="white-space: pre-wrap;">In announce letter 915-238, all license part numbers were withdrawn from marketing effective March 10, 2016 for  Dxxxxxx and April 12, 2016 for Exxxxxx. The V6.4 media is still available for electronic download only.</p>

Open in new window


Using this PowerShell command I can retrieve the H3 Class Value right before it (i.e. the Comment text string), but for whatever reason I cannot figure out to get the P Style text value.

($HTML.ParsedHtml.GetElementsByTagName("h3") | Where{ $_.className -eq 'ibm-h4 ibm-light ibm-padding-top-r1' }).innerText

Open in new window


Capture.PNG
Really appreciate any help.
0
I am using Powershell to try and read in a delimited file and and parse out the information so I can use it for processing.
I have attached a sample of the file that I would be reading, and am not sure how to parse it out into something usable in Powershell.
The first row of the file are headers and the second row are the corresponding data for those headers. What is the best way to handle this data?

For example - I am trying to assign the "Salesman" corresponding value in row 2 to a variable in my Powershell script. Any suggestions on how to accomplish this.
Example.txt
0
I would like a script or program where I could specify a server and a top level share and the script will walk the entire structure including all sub directories and will generate a report as a.csv file with the information and format shown in the attached screen shot. I only want explicit permissions shown, not inherited permissions.
This doesn't have to be PowerShell. It could be .vbs or other language. I just need to get the output in the format I'm looking for.
0
can anyone assist with powershell select-string. I have a huge txt file which is a row by row report, and I need to export only rows from the huge report out to a seperate file, where it finds a specific keyword in the row of data, it would need to be *keyword* as it could be in a column on its own, or within a string of text in another column. So I basically need to specify the file to search, the search term, and then export any rows from the file to search where it finds the keyword, and exports it to a separate file.
0
If any invalid samaccountname mentioned in the input file , the output will be as “NOTFOUND” with empty username field. Any possible way that  if invalid samaccountname found in the input file the output should be  “NOTFOUND” with invalid username in the username column

Import-Module ActiveDirectory
Get-Content -Path "C:\Temp\new\input.txt" | ForEach-Object {
	If ($ADUser = Get-ADUser -Filter "samAccountName -eq '$_'" -Properties ExtensionName, Company) {
		$ADUser | Select-Object -Property SamAccountName, @{n='ExtensionName'; e={$_.extensionName -join ', '}}, Company, @{n='Error'; e={''}}
	} Else {
		'' | Select-Object -Property SamAccountName, ExtensionName, Company, @{n='Error'; e={'<NOT FOUND>'}}
	}
} | Export-Csv C:\values.csv -Append -NoTypeInformation 

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals
LVL 12
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Hello, how can i find the max message size on the organizational level on Exchange 2016?

If theres a way to check without powershell that would be preferred.
0
Is it possible to control the output of the following script such that it will only show header once when looping through logfiles in a folder ?  Thx

Result
---------
date       time     Username    IP            UserAgent              
----       ----     --------    --            ---------              
2018-07-07 19:46:49 abc\johnlee 40.69.186.133 Outlook-iOS-Android/1.0
2018-07-07 20:40:50 abc\johnlee 40.69.186.133 Outlook-iOS-Android/1.0

date       time     Username    IP            UserAgent              
----       ----     --------    --            ---------              
2018-07-07 19:46:49 abc\johnlee 40.69.186.133 Outlook-iOS-Android/1.0
2018-07-07 20:40:50 abc\johnlee 40.69.186.133 Outlook-iOS-Android/1.0

Powershell Script
-------------------------
$userName = "johnlee"

$logFile = Get-ChildItem C:\Temp -Recurse -Include myTest* |  Select-Object -First 1 | Select FullName
$logFiles = Get-ChildItem C:\Temp -Recurse -Include myTest* | Select FullName

$header = (Get-Content -Path $logFile.FullName -TotalCount 4)[-1] -replace '\A#Fields:\s' -split ' '
 
foreach ($currentlog in $logFiles) {
  Get-Content -Path $currentlog.FullName | Select-Object -Skip 4 | ConvertFrom-Csv -Header $header -Delimiter ' ' |
      Where-Object {$_.'cs-username' -Match $userName} |
      Select-Object -Property Date, Time, @{n='Username'; e={$_.'cs-username'}}, @{n='IP'; e={$_.'c-ip'}}, @{n='UserAgent'; e={$_.'cs(User-Agent)'}} | Format-Table -AutoSize}
1
Hi,

Before say VCheck (:-)), I d need a Ps based health of a specific cluster, like you can find in the Vcenter GUI of a cluster: this many CPU of max is used, this much storage of all storage, mem.of all mem available. Those 3 values,
nothing more then that. Any advise welcome.

J
0
I am trying to run
search-mailbox -Identity "user@domain.com" -SearchQuery subject:"credit card" -DeleteContent

but it says search-mailbox is not recognized as name of commandlet

I have outlook 2010 and running on powershell connected to office 365 user mailboxes
0
I would like some Powershell help.

I have a service that will intermittently lockup. The service manager still reports it as running, and the only way is to recover the situation is
a) Stop the process in SCM.... wait and it will report that the service could not be shutdown ( cant remember exact message)
b) Taskmgr - Kill the process
c) Start the process in SCM.

I would like to run a scheduled task that daily runs a powershell script that tries the following.
$servicename = Get-Service | where-object {$_.name -like '*Application1*'}
$process =  Get-WmiObject Win32_Process | Where-object {$_.CommandLine -Like "*\bin\tomcat*"}

a) attempt to stop ( or re-start ) $servicename.
b) only if $servicename does not stop, then $process.Terminate()
c) start service.

Any help appreciated
0
We need a rule that forwards all of userA'S meeting responses (accept, decline, tentative) and forwards them to USER B now automatically and does not appear in his inbox.  Is this possible?

Can we give delegate access through some powershell command

users mailboxes are in office 365
0
How to write a powershell to read the attachment Exchange log file and filter a particular user "johnlee" and extract the date, time , username, IP and device ?

Thx
0
Dear Powershell experts.. Powershell script issue

We want to move .jpg files beginning with "DRS_" or "DRS-" from local computer directory to a remote computer directory, ultimately.
We want the script to check every 30 seconds (or loop if applicable) if the source folder has above jpg file types in it and if so run the PS "move-item" functions. Testing with just the "move-item" function lines on their own works.


My problem seems to be in the construct on logic of the section below which seems to be ignored right now:
$timeout = 120
$sw = [diagnostics.stopwatch]::StartNew()
while ($sw.elapsed -lt $timeout)
{
    if (Test-Path $Source1 -include DRS*.jpg){
        write-host "Found a file!"
    return

Please help fix it.

Thankyou. See attached script.
0
script with powershell 5.1, I need a little help getting the input working the way I'd like, I have this script and it works great with a servers.txt input, or read-host. I'd like the read-host to be able to take several system names, all my efforts keep returning the error:
Invoke-Command : One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.
I tried quotes, commas, double quotes, still get an error that the name is wrong.
$server = Read-host "Enter server names"
#$servers = gc .\servers.txt
foreach ($server in $servers) {
Invoke-Command -computername $server -scriptblock {Get-LocalGroupMember -group "administrators"}
}

Open in new window


What do I need to do to be able to have more than one server from read-host?
0
Cloud Class® Course: Microsoft Office 2010
LVL 12
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Hi Experts,

One of my customers runs a mixed on prem Exchange 2010 - 2016 organization with 20 Exchange 2016 MBX servers among different AD sites, and 10 Exchange 2010 servers in several AD sites.

Since we are in the process of migrating mailboxes, we are looking to build a script to run following queries, and return the values in CSV files. I need your help either to provide the right cmdlets or a script to do:

1. get a query of all legacy mailboxes hosted only in Exchange 2010 servers per site. This query should return only mailboxes in Exchange 2010 per site and the values of the csv output file should contain:  Display Name, email address, useraccount, Manager, database

2.  Get all mailboxes in Exchange 2016 servers and  per site. Only mailboxes hosted in Exchange 2016 databases should be returned and listed on a CSV file. As per above, it should include all parameters above.

Any help is highly appreciated

Cheers
0
Hi Experts

I am planning for a merge of 3 different Office 365 tenancies into one.
I am trying to get a clean list of
  • Mailboxes
  • Main email address
  • Alias emails address(es) if any

All the powershell scripts I could find would give the alias email addresses as follow

SPO:SPO_xxx@SPO__xxx SIP:name1@company.com SMTP:name1@company.com smtp:name1@company.onmicrosoft.com smtp:name2@company.com smtp:name3@company.com X500:/stuff_here with space and /

Open in new window


Note, these can be in any order
smtp:name2@company.com SMTP:name1@company.com smtp:name1@company.onmicrosoft.com SIP:name1@company.com smtp:name3@company.com SPO:SPO_xxx@SPO__xxx 

Open in new window

or might not have all types of addresses
SMTP:name1@company.com smtp:name1@company.onmicrosoft.com SIP:name1@company.com smtp:name3@company.com SPO:SPO_xxx@SPO__xxx 

Open in new window

From the above, I would like to extract the following
name1@company.com, name2@company.com, name3@company.com

Open in new window

1st one is "SMTP:"
the next one are "smtp:" in any order

and thus I would like to drop the following
SPO:SPO_xxx@SPO__xxx (because it starts with "SPO:") 
SIP:name1@company.com (because it starts with  "SIP:")
X500:/stuff_here with space and several /  (because it starts with "X500:") 
smtp:name1@company.onmicrosoft.com  (because it ends with ".onmicrosoft.com")

Open in new window


I have tried to do this in Excel, but it is getting too hard

Clarification: What I am realy trying to do is to re-import all these addresses into the new tenancy, so if there is another way to export/import or sync email addresses, I am opened to alterative solutions
0
Hi,

How can I check if a O365 acuser is in softdeleted status and if it the case restore it. I have a list of users UPN from csv file and need to check all.

Thanks
0
When trying to install an application with powershell, it doesn't.
Here is the  script I run, the files copy over just fine, but it does not actually install.
$computerName = Read-Host "Enter your VM name"
Copy-Item -Path \\servername\c$\AgentInstalls\FireEye\xagtSetup_26.21.8_universal.msi -Destination "\\$computername\c$\windows\temp\xagtSetup_26.21.8_universal.msi"
Copy-Item -Path "\\servername\e$\AgentInstalls\FireEye\agent_config.json" -Destination "\\$computername\c$\windows\temp\agent_config.json"
Invoke-Command -ComputerName $computerName -ScriptBlock {
    c:\windows\temp\xagtSetup_26.21.8_universal.msi /silent
}

Open in new window

0
I need to import a spreadsheet containing phone number, fax number and telephone into our Active directory current objects for about 50 current users.
Do anyone have any script / help me how to attain this task through powershell ?

Thanks

Danny
0
Hi all.

I have a small script which I found and have used to encrypt Azure VM instances. Here it is - note, everything is hard-coded so each time I run it I have to edit the script. t Can anyone modify this so that when I run the script, I get prompted to add the names dynamically, so using parameters?

    $RGName = "MyTestRG"
    $VMName = "MyTestVM"
    $VaultName= "MyTestVault"
    $KeyVault = Get-AzureRmKeyVault -VaultName $VaultName -ResourceGroupName $RGName
   $DiskEncryptionKeyVaultUrl = 'MyVaultURL'
   

Thank you
0

Powershell

17K

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.