PrivateFunctions/tset.ps1


Upload-FileToOneDrive -userPrincipalName admin@BitTitanYixiaoDev1.onmicrosoft.com -filePath C:\Users\yshen\Desktop\pw.txt -destinationFilePath shit/ss/fuck/cao.txt -endpoint $Office365AdministrativeCredentials
Upload-FileToOneDrive -userPrincipalName admin@BitTitanYixiaoDev1.onmicrosoft.com -filePath C:\Users\yshen\Desktop\file.zip -destinationFilePath shit/ss/fuck/cao.zip -endpoint $Office365AdministrativeCredentials
# C:\Users\yshen\Desktop\file.zip
$userPrincipalName = 'admin@BitTitanYixiaoDev1.onmicrosoft.com'
$token = Get-MicrosoftGraphAuthenticationToken -Endpoint $Office365AdministrativeCredentials
$filePath = 'C:\Users\yshen\Desktop\pw.txt'
$destinationPath = 'shit/ss/fuck/SG Seat Plan Jan 7, 2019.png'
$destinationPath = 'shit/ss/fuck/1.zip'
$destinationFilePath = 'shit/ss/fuck/111.zip'
$invokeRestMethodParams = @{
    Uri     = "https://api.office.com/discovery/v2.0/me/services"
    Method  = "GET"
    Headers = @{
        Accept          = "application/json"
        Authorization   = "bearer $($token)"
    }
}

$invokeRestMethodParams = @{
    Uri     = "https://graph.microsoft.com/v1.0/users/$($userPrincipalName)/drive/root:/folder22/222/shit/fuck/pw.txt"
    Method  = "DELETE"
    Headers = @{
        Accept          = "application/json"
        #"Content-Type" = "text/plain"
        Authorization   = "bearer $($token)"
    }
    #Body = ((Get-Content -Path $filePath -Encoding Byte | ForEach-Object -Process { [Char]$_ }) -join "")
}
$invokeRestMethodParams = @{
    Uri     = "https://graph.microsoft.com/v1.0/users/$($userPrincipalName)/drive/root:/folder22/222/shit/fuck/pw.txt"
    Method  = "GET"
    Headers = @{
        Accept          = "application/json"
        #"Content-Type" = "text/plain"
        Authorization   = "bearer $($token)"
    }
    #Body = ((Get-Content -Path $filePath -Encoding Byte | ForEach-Object -Process { [Char]$_ }) -join "")
}
$invokeRestMethodParams = @{
    Uri     = "https://graph.microsoft.com/v1.0/users/$($userPrincipalName)/drive/root:/folder22/222/shit/fuck/pw.txt"
    Method  = "PUT"
    Headers = @{
        Accept          = "application/json"
        "Content-Type"  = "text/plain"
        Authorization   = "bearer $($token)"
    }
    Body = ((Get-Content -Path $filePath -Encoding Byte | ForEach-Object -Process { [Char]$_ }) -join "")
}

# Upload
$invokeRestMethodParams = @{
    Uri     = "https://graph.microsoft.com/v1.0/users/$($userPrincipalName)/drive/root:/$($destinationPath):/content"
    Method  = "PUT"
    Headers = @{
        Accept          = "application/json"
        "Content-Type"  = "text/plain"
        Authorization   = "bearer $($token)"
    }
    Body = ((Get-Content -Path $filePath -Encoding Byte | ForEach-Object -Process { [Char]$_ }) -join "")
}
$response = Invoke-RestMethod @invokeRestMethodParams

# Download
$invokeRestMethodParams = @{
    Uri     = "https://graph.microsoft.com/v1.0/users/$($userPrincipalName)/drive/root:/$($destinationPath)"
    Method  = "Get"
    Headers = @{
        Accept          = "application/json"
        #"Content-Type" = "text/plain"
        Authorization   = "bearer $($token)"
    }
    #Body = ((Get-Content -Path $filePath -Encoding Byte | ForEach-Object -Process { [Char]$_ }) -join "")
}
$response = Invoke-RestMethod @invokeRestMethodParams
$downloadUrl = $response.'@microsoft.graph.downloadUrl'
Get-FileFromUrl -fileUrl $downloadUrl -destinationPath 'C:\Users\yshen\Desktop\newfolder\file.png'

# Delete
$invokeRestMethodParams = @{
    Uri     = "https://graph.microsoft.com/v1.0/users/$($userPrincipalName)/drive/root:/$($destinationPath)"
    Method  = "DELETE"
    Headers = @{
        Accept          = "application/json"
        #"Content-Type" = "text/plain"
        Authorization   = "bearer $($token)"
    }
    #Body = ((Get-Content -Path $filePath -Encoding Byte | ForEach-Object -Process { [Char]$_ }) -join "")
}
$response = Invoke-RestMethod @invokeRestMethodParams