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

Powershell Commands Office 365

$
0
0

I am looking for a way that i can use Powershell to display all current active sessions that a user has. For instance, i want to be able to see that i am logged into my iPhone and my Laptop and my Desktop. Is this possible? 


Rename-Computer Script Errors but works

$
0
0

Hi- Working on this script:

Text
PS C:\Windows\system32 $a = Import-Csv c:\users\TheDude\desktop\rename.csv -Header OldName, NewName Foreach ( $Server in $a ) {Rename-Computer -ComputerName $Server.OldName -NewName $Server.NewName -DomainCredential Domain\TheDude -Force} 

[Prompt for password]

Followed by this error:


Rename-Computer : Computer name OldName cannot be resolved with the exception: No such host is known.
At line:2 char:28
+ Foreach ( $Server in $a ) {Rename-Computer -ComputerName $Server.OldName -NewNam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (OldName:String) [Rename-Computer], InvalidOperationException
+ FullyQualifiedErrorId : AddressResolutionException,Microsoft.PowerShell.Commands.RenameComputerCommand

[Prompt for password again]

Followed...

Give a user access to multiple calendars Exchange Online Power Shell

$
0
0

Hi lads,

I know how to grant Calendar permissions to a group. The line below will give everyone from the group access to a Calendar.

add-MailboxFolderPermission -Identity USERID:\Calendar -User Sercuritygroupname -AccessRights Owner

But how to Grant permissions the other way around? e.g. 1 user have access to 50 calendars.

I have a task to give a user access to 50 calendars. I don't want to do it one by one.

Thanks for your help.

PowerShell script to replication of all Domain Controllers on all Sites

$
0
0

I'm look for a PowerShell script to forcereplication of all Domain Controllers on all Sites.

I found the one below on the Internet but it doesn't seem to work. It runs and says "SynchAll Finished with no errors" but doesn't replicate the AD changes.

If anybody can give me a script that works that would greatly appreciated.

Thanks

Powershell
Import-ModuleActiveDirectory$DCs=(Get-ADForest).Domains|%{Get-ADDomainController-Filter*-Server$_}|selectHostNameforeach($DCin$DCs){repadmin/syncall$DC.HostName}

How to prompt for credentials from script in MDT task sequence

$
0
0

Hi all I am trying to do a domain join in MDT, but don't want to put the password in the customsettings.in nor in the domain join script. I want the task sequence to prompt for the password. Normally I could use the wizard, but I am delaying the domain join till the end of the process. The error below is what the task generates. I know what it means, but not sure to get past it so the task prompts for credentials.

*******************************************************
The method or operation is not implemented. TaskSequencePSHost 1/25/2019 13:12:55 0 (0x0000) At \\VIRM-MDT-DC01\VIRMShare$\Scripts\SubScripts\join_domain_with_Prompt.ps1:4 char:13 + $password = Read-Host -Prompt "Enter password for $user" -AsSecureStr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TaskSequencePSHost 1/25/2019 13:12:55 0 (0x0000)...

How to use the foreach loop in powershell?

$
0
0

This is a Auto print script i'm trying to make for gsuite. I use psgsuite module. The script saves all attachments that go to payables@domain.com to a network share. On the user computer a script then runs to check the folder for files and print any pdf's that are located in that folder. I need help on how to do this to all the emails (email id's) in a loop.

Powershell
## Save attachments from payables@domain.com to network folder$email=((Get-GSGmailMessageList-User"payables@domain.com")|Select-ObjectId|Format-Table-HideTableHeaders)ForEach$email{Get-GSGmailMessage-User"payables@domain.com"-Id($_)}

The id needing to be a string that changes based on the email ID

Reducing Office 365 Licenses With Powershell

$
0
0

Hello Spiceheads,

I've made an employee termination powershell script that automates a great deal of our workflow for departing employees. I want to add more features to it, so I'm working on having the script auto remove office 365 licenses. I have been able to use this powershell code to remove all licenses from users (thanks Neally)

Powershell
functionremoveLicenses{(get-MsolUser-UserPrincipalName$termUPN).licenses.AccountSkuId|foreach{Set-MsolUserLicense-UserPrincipalName$termUPN-RemoveLicenses$_}}

This code works great, however I still have licenses in my account. Does anybody know a powershell command to lower the number of licenses (as is displayed inGet-MsolAccountSku) I've also attached a picture of the admin console view online.


Basically, I want to have it remove the license so that purchased licenses is equal...

Reducing Office 365 Licenses With Powershell

$
0
0

Hello Spiceheads,

I've made an employee termination powershell script that automates a great deal of our workflow for departing employees. I want to add more features to it, so I'm working on having the script auto remove office 365 licenses. I have been able to use this powershell code to remove all licenses from users (thanks Neally)

Powershell
functionremoveLicenses{(get-MsolUser-UserPrincipalName$termUPN).licenses.AccountSkuId|foreach{Set-MsolUserLicense-UserPrincipalName$termUPN-RemoveLicenses$_}}

This code works great, however I still have licenses in my account. Does anybody know a powershell command to lower the number of licenses (as is displayed inGet-MsolAccountSku) I've also attached a picture of the admin console view online.


Basically, I want to have it remove the license so that purchased licenses is equal...


No PS-Remoting: "Test-WSman" works locally, but fails from any other machine

$
0
0

Hi everyone, I'm trying to setup a GPO to simply enable PS-Remoting but having trouble. When I run the PowerShell command `Test-WSman` it works locally, but fails from any other machine I try:

Powershell
PSC:\Test-WSManWin10-LTSCTest-WSMan:<f:WSManFaultxmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault"Code="2150858770"Machine="Dell-Precision.MyLab.local"<f:MessageTheclientcannotconnecttothedestinationspecifiedintherequest.Verifythattheserviceonthedestinationisrunningandisacceptingrequests.ConsultthelogsanddocumentationfortheWS-Managementservicerunningonthedestination,mostcommonlyIISorWinRM.IfthedestinationistheWinRMservice,runthefollowingcommandonthedestinationtoanalyzeandconfiguretheWinRMservice:"winrm quickconfig".f:Messagef:WSManFaultAtline:1char:1...<<

adding 100 users using powershell (windows server 2012)

$
0
0

hi ive tryed to use this on windows server 2012 R2

Import-Module ActiveDirectory foreach($i in 1..100) { $AccountName = "Student{0}" -f $i $SecurePassword = "Password01" | ConvertTo-SecureString -AsPlaintext -Force New-ADUser -Name $AccountName -AccountPassword $SecurePassword -Path "OU=Bulk,DC=ad,DC=DC2,DC=local" -Enabled:$true }

but its didnt worked well -

it says -

new-ADUser : the server is unwilling to process the request

new-ADUser -name $AccountName -accountPassword $SecurePassword -path "ou=bulk,DC +categoryinfo : notspecified (cn=student1,ou=...=DC2,DC=local:string) [new-aduser], ADException
+fullyqualifiederrorid : activedirectoryServer:0,microsoft,activedirectory,managment,commands,newaduser

100times

this is myDetails:

computer name:DC2

domain-name:beeriprint

OU:bulk

users:student1-100

password: password01

THANKS alot :)

Import-Csv not handling blank fields on AD contact import

$
0
0

We are using a cloud GAL Sync solution that will sync users from multiple O365 tenants into each others GAL as contacts so all the orgs can have a single GAL. This works great for O365, but since this info does not sync back down to the local AD environments, we cannot see these contacts on devices like Multi-Function Printers unless they sync down to AD.

I have a draft script below that will import Contacts from O365 down to my local AD (Still working on stored credential security). It work fine when every fields in the CSV exported from O365 is populated, but when it hits a blank field it does not import that record.

I need a way to have the Import-Csv command ignore blanks

(After I get this working I will break it up into several steps to check for existing contacts and do an update instead)

...

Clean up output of batch file

$
0
0

Hey guys i"m in the process of learning power shell. I've got this code to check the windows activation and it works fine. i have an input.txt with ip inputs and a output.txt to get the results. but I'm wanting to make the output say "Activated" or "Not" instead of the "1" i get if its licensed and a " " blank spot if it isn't.

Can anyone tell me why the code uses export-csv but i have to use text files to get it to work, i don't mind just curious?

Any help would be appreciated, even if its just pointing me to the right code

Batchfile
param([string]$fileInput,[string]$fileOutput ) If ( $fileInput -eq "" -OR $fileOutput -eq ""){ Write-Host Write-Host Write-Host "--------------------------------------------------" Write-Host "getLicenseStatus.ps1" Write-Host Write-Host "Usage: .\getLicenseStatus.ps1 " Write-Host ...

need help yith output for GUI + runspaces

$
0
0

Hi,

I'm working on a personnal project and try to learn about GUI and runspaces for multithreading purpose.

I would like to run commands ( ping , os info, network info ...) for all computers in the listview " selected computers"

open a runspacepool for each computer

the output (wich is different for each command) should be outputted in the listview "Output"

My issue if for the formating and the output data

any help would be very appreciated

here is a part of my code

##########################################################################################
# Load Assembly and Library
##########################################################################################

try{
Add-Type -AssemblyName PresentationCore,PresentationFramework,WindowsBase,system.windows.forms
} catch {
Throw "Failed to load Windows Presentation Framework assemblies."
}

...

Powershell list memebership of csv users

$
0
0

Hello everyone,

I got a list of users in a CSV file (actives.csv) and I have to list the user and its AD memeberships in a csv output file.


Text
$actives = import-csv -path "C:\Users\hello\Desktop\HR_Data\actives.csv" 

any help is highly appreciated.

I found a partial suggestion listed below but I have to only search for the users from the HR list and output saved in csv format.

Text
$actives = import-csv -path "C:\Users\hello\Desktop\HR_Data\actives.csv" 
Text
Import-Module ActiveDirectory If ($UserName) {   $UserName = $UserName.ToUpper().Trim()   $Res = (Get-ADPrincipalGroupMembership $UserName | Measure-Object).Count   If ($Res -GT 0) {     Write-Output "`n"     Write-Output "The User $UserName Is A Member Of The Following Groups:"     Write-Output "==========================================================="    ...

Powershell list group membership of csv users

$
0
0

Hello everyone,

I got a list of users in a CSV file (actives.csv) and I have to list the user and its AD memeberships in a csv output file.


Text
$actives = import-csv -path "C:\Users\hello\Desktop\HR_Data\actives.csv" 

any help is highly appreciated.

I found a partial suggestion listed below but I have to only search for the users from the HR list and output saved in csv format.

Text
$actives = import-csv -path "C:\Users\hello\Desktop\HR_Data\actives.csv" 
Text
Import-Module ActiveDirectory If ($UserName) {   $UserName = $UserName.ToUpper().Trim()   $Res = (Get-ADPrincipalGroupMembership $UserName | Measure-Object).Count   If ($Res -GT 0) {     Write-Output "`n"     Write-Output "The User $UserName Is A Member Of The Following Groups:"     Write-Output "==========================================================="    ...

FIrstname Surname

$
0
0

hi guys,

I have been given a list of users from a legacy system (not AD username) and i have been asked to try and match as many users up as possible with their AD counterpart, i have made the following but it seems to get a bit stuck on the surname check:-

Powershell
Import-ModuleActiveDirectory$First=Import-Csv"c:\test\test\users.csv"|select-Expandpropertyfirst$SN=Import-Csv"c:\test\test\users.csv"|select-ExpandpropertysnForEach($userin$first){$pers=Get-ADUser-Filter*|wheregivenName-eq$user|Selectsamaccountnameforeach($namein$pers){Get-ADUser$name|wheresurname-eq$sn|SelectsAMAccountName,name|export-csv"C:\Test\TEST\test.csv"-NoTypeInformation}}

I am not get anything in the $pers

My CSV has headers First and SN with the users names under this

Connecting to Office365 using PS Function. Can't get cmdlets to work.

$
0
0

I'm trying to use the following function to connect to Office 365 and then run commands outside of the function. If I run the function outside of the function block it works fine, but I keep it in a psm1 and it doesn't allow me to run, for example Get-Mailbox.

Powershell
functionConnect-Exchange365{param()$AESKeyFilePath=**$credentialFilePath=**$passwordSecureString=$Creds.Password$username=**$AESKey=Get-Content$AESKeyFilePath$pwdTxt=Get-Content$credentialFilePath$securePwd=$pwdTxt|ConvertTo-SecureString-Key$AESKey$credObject=New-ObjectSystem.Management.Automation.PSCredential-ArgumentList$username,$securePwd#Opens a Portal the the Exchange Realm$exchangeSession=New-PSSession-ConfigurationNameMicrosoft.Exchange-ConnectionUri**-Credential$credObject-Authentication"Basic"-AllowRedirection...

Try and Catch not working

$
0
0

I am trying to run gpresults remotely. It works but only on one machine instead of the entire list that is in the txt file. 

Here is the code

Text
Function get-test(){

$Computers = get-content C:\Users\AdministratorDocuments\WindowsPowerShell\Scripts\Listlaptops.txt

try{

foreach($CO in $Computers){


get-gpresultantsetofpolicy -Computer $CO -ReportType HTML -path C:\Users\Administrator\Documents\WindowsPowerShell\Scripts\$CO.html
}
}
catch [System.Runtime.InteropServices.COMException]{
Write-Host "The $CO is offline"}
}

As soon as I get rid of "try and catch" it works as expected but you get a ton of RPC errors instead of the message. Do I need to add another foreach cmdlet inside catch? 

Entry to power shell class?

$
0
0

Hello I am looking for a entry level powershell class or book. I have used powershell and I can copy and paste scripts together but I’m looking to boost my knowledge. I am a new systems administrator so I’m looking for things like pulling info from file shares, AD and automating simple tasks.
curious if anyone has recommendations.
Thanks for any suggestions!

Help with import-csv

$
0
0

Hello,

I tried searching this, but due to the type of problem it seemed to be hard to word in order to find a current answer on this.

I have always been able to import a csv file and then create a user in o365 as such new-msoluser -displayname $_.displayname -userprincipalname $_.userprincipalname - etc...

All the sudden i am running into issue where it will not take the $_. variable saying "you must provide a required property: parameter name: userprincipalname" and it does the same with displayname, but it seems to take the first and last name variables from the csv. 

Any help is greatly appreciated. I am sure its just me.

Viewing all 15370 articles
Browse latest View live


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